dsm has asked for the wisdom of the Perl Monks concerning the following question:
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:
any help would be much appreciated! Thanks, dsm#!/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);
|
|---|
| 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 |