Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Sendmail problem

by himajin (Initiate)
on Mar 22, 2008 at 15:29 UTC ( [id://675645]=perlquestion: print w/replies, xml ) Need Help??

himajin has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm having trouble getting the right "From: " in emails sent using sendmail. If I define my $sender as an email address, it works fine, but when I try to read the email in as a parameter from a form, when the mail is delivered, it appears as: "emailaddress@domain.com"@myservername How can I stop it from putting it in quotes and attaching the server name? (I'm not sure if the problem is coming from the sendmail part or the parameter reading part, so I put in both). Parameter reading:
use CGI qw(:standard); @paramater=param(); $numberofparamaters=@paramater; $i=0; while ($i<$numberofparamaters) { @data[$i] = param(@paramater[$i]); if (@paramater[$i] =~ /email/) { $sender=@data[$i]; } $i++; } $sender =~ s/@/\\@/;
Sendmail:
my ($to, $from, $subject, $message) = @_; my $sendmail = '/usr/sbin/sendmail'; open(MAIL, "|$sendmail"); print MAIL "From: $sender\n"; print MAIL "To: ???\@gmail.com\n"; print MAIL "Subject: Amapro signup\n\n"; $i=0; while ($i<$numberofparamaters) { print MAIL "@paramater[$i]"; print MAIL ": "; @data[$i] = param(@paramater[$i]); print MAIL @data[$i]; print MAIL "\n"; $i++; } close(MAIL);

Replies are listed 'Best First'.
Re: Sendmail problem
by pc88mxer (Vicar) on Mar 22, 2008 at 19:59 UTC
    To elaborate on the above response, I think the culprit is:
    $sender =~ s/@/\\@/;
    (Note that the s/@/\@/ in the above response do not actually change anything.) In general there shouldn't be any need to escape at-signs in your email addresses. If you do, sendmail will add @yourdomain.com to fully qualify the address.

    In this line:

    print MAIL "To: ???\@gmail.com\n";
    you need to escape the @ only because it is in a double-quoted string and you don't want it to be interpreted as array interpolation. If you used a single-quoted string you wouldn't need the backslash. However, in previous line:
    print MAIL "From: $sender\n";
    there is no need to escape any at-signs in $sender - its value will be inserted without any further interpretation.
      Thanks so much! I really appreciate your help because I spent hours on this yesterday. It works great now.
Re: Sendmail problem
by doc_faustroll (Scribe) on Mar 22, 2008 at 16:21 UTC
    The below works just fine:
    #assuming email_address was declared and currently has no escapes #print "from is $from_string\n"; $email_address =~ s/@/\@/; $from_string =~ s/@/\@/; open( SENDMAIL, "|/usr/lib/sendmail -oi -t" ) or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; From: $from_string To: $email_address Subject: $subject Content-type: text/html $$textref EOF close(SENDMAIL) or warn "sendmail didn't close nicely"; print qq ( email sent to $email_address\n);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://675645]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-25 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found