#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0

    FROM address using sendmail in perl


    does anyone know how to change the FROM address using sendmail in a perl script? this script is a form mailer.

    right now the from address is the default, generated by my ISP's server. When sending a reply to that addres, it gets bounced. I want the from addres point to any address that I specify. That is because I use this script to send form data to various e-mail addresses of my customer. Whenever they reply to that mail I want to be able to receive those replies.

    thanks, Eric
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    If you post the code that's setting To, Subject etc. we should be able to add to it easily enough.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    Hi,
    here is part of my code that handles the e-mail. thanx in advance


    $mailprog = '/usr/sbin/sendmail -t';
    $recipient = 'recipient@somedomain.com';

    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);

    foreach $pair (@pairs)
    {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }

    open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
    print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
    print MAIL "Subject: Subscription for the Security Summit\n\n";
    print MAIL "$FORM{'name'} subscribed for the Security Summit\n\n";
    print MAIL "------------------------------------------------------------\n";
    print MAIL "Name: $FORM{'name'}\n\n";
    print MAIL "Extra registrations: $FORM{'extra'}\n";
    print MAIL "Organisation: $FORM{'organisation'}\n";
    print MAIL "Function: $FORM{'function'}\n";
    print MAIL "Address: $FORM{'address'}\n";
    print MAIL "City: $FORM{'city'}\n";
    print MAIL "Postal code: $FORM{'postal'}\n";
    print MAIL "Telephone Number: $FORM{'telephone'}\n";
    print MAIL "E-mail: $FORM{'email'}\n\n";
    print MAIL "\n------------------------------------------------------------\n";
    print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
    print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
    print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
    close (MAIL);
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    Firstly, you really should use CGI.pm for parsing forms.

    There's probably a better way to do it but putting the following in after you've opened sendmail should have the desired effect:
    Code:
    print MAIL "From: John Doe <johndoe\@somehost.com>\n";
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    Thank you for your quick reponds Ishnid!

    obvious the solution you gave me was so simple.
    My script now works. So thanks for that!

    I use an old mailform script that I have used now for over a few years and it works okay. But indeed it doesn't use the CGI.pm. Can you tell me in three words why the form parsing is better with CGI.pm?

    Eric
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    I found this great artical about CGI.pm on the devshed website that seems to explain everything. So I'll start reading that.

    eric
  12. #7
  13. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    Originally posted by ebonit
    Can you tell me in three words why the form parsing is better with CGI.pm?
    Three words? That's a tough one. Do you mind if I cheat a little? What about this:

    Here's a link

    3 words!
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0

    Smile


  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    I found something else that doesn't go right. The email addres from $FORM{'email'} gets chopped. No matter what e-mail addres I put in, it chops of the last character.

    print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
    print MAIL "E-mail: $FORM{'email'}\n\n";


    Any clue?
  18. #10
  19. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    There must be a chop in your code somewhere. chomp only chops newline characters AFAIK

    If you can't find the problem, add a character using Javascript on Submit ... not for real

    --Ax
  20. #11
  21. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    There's probably no reason to use Reply-to. It will reply to the sender if you leave it out.
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    if I don't use the reply-to then sendmail generates the reply address itself like this:

    recipient@recipientaddres.com@jean.aetserver.nl

    jean.eatserver.nl is the server that handels the sendmail. When I don't use the from: line at all then the from address will be jean@eatserver.nl



    There is no chop in my code.
    My form is handled by flash. I can't emagine that flash is doing something weird but I'll have a look into that as soon as I find the time.

    thanks guys!
  24. #13
  25. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    If you think it might be the flash, add another field after e-mail called XXX, and if logic being what it is ... flawed, it should chop the $FORM{'XXX'} variable.
    ishnid is right though have a good look a CGI.
    --Ax
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    that is a smart one! I'll try that for sure. the email field is also the last field that is in the form itself.

    I'll look into the CGI.pm I'll have to get familiar with the coding though and Ijust don't have the time right now because this form thing is just a small part of a bigger project I am working on. And my customer wants to see something in like two hours. But I'll surely look into it and build myself a new script.
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    The Netherlands
    Posts
    9
    Rep Power
    0
    that hidden field seems to do the trick

    thanks, Eric

IMN logo majestic logo threadwatch logo seochat tools logo