Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

getting the correct 'from' field when sending mail

by dsm (Novice)
on Jul 14, 2003 at 11:48 UTC ( [id://273950]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I'm using Mail::Mailer to send an email to a bunch of email address i read from a text file...problem is, the 'from' field doesn't come up correctly - the actual from field is saying my email address from the system which is running the perl script, but then in the body of the message it has up the top: From: correct_email@address.com how can i get it so that the actual from field has this address? following is my code:

#!/usr/bin/perl -w #this program emails to a list of people stored in the file address.tx +t #address.txt is of the form: first name <space> second name <tab> emai +l use strict; use Mail::Mailer; sub splitStuff{ #split the text file into appropriate fields open(INFILE, "2address.txt"); my $from_address = "correct_email\@address.com"; my $subject = "test email - ignore"; my $to_address; my ($name, $firstnm, $lastnm); while (<INFILE>) { my $line = $_; ($name, $to_address)=split("\t"); ($firstnm, $lastnm)=split(" ", $name); if ($to_address !~ /\@/) { print "There is no email address for $ +name. No e mail sent. \n"; next; } &mail($to_address, $from_address, $subject, $firstnm, $lastnm); print "Email sent to $firstnm $lastnm, email: $to_addr +ess \n"; } } sub mail () { my ($to_address, $from_address, $subject, $firstnm, $lastnm) = + @_; #body my $body="hello $firstnm, \n how are you"; my $mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => $from_address, To => $to_address, Subject => $subject, }) or die ("error $firstnm, $lastnm"); print $mailer $body; $mailer->close(); } &splitStuff; close(INFILE);
any help would be much appreciated! Thanks, dsm

Replies are listed 'Best First'.
Re: getting the correct 'from' field when sending mail
by gellyfish (Monsignor) on Jul 14, 2003 at 11:52 UTC

    I think you will find that it is because you are not chomping the data read from INFILE - this causes the To: header to have an additional newline which is interpreted as the end of the headers

    /J\
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-25 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found