View Full Version : Help with configuring sendmail "from" field--automatically adds my domain name?

03-12-2011, 12:45 PM
I'm writing a Perl script to automatically send an e-mail to people under certain circumstances. I've only just started, so right now I just have a very basic script which is supposed to send a test e-mail to my other e-mail address whenever I run it. But the problem I'm having is that it won't put the correct name in the "From" field. For instance, the line

print SENDMAIL "From: Tom Jones\n";

causes the e-mail I receive to say "Tom.Jones@heroofcamelot.com" as the sender's name when I receive the e-mail. Just so this is clear, when I say the "from name" I'm talking about the name it's supposed to say the person came from when you get the e-mail. I'm not talking about the reply-to address, that works fine. But just displaying the person's name. Like usually when you open your Inbox, it shows the name of the person each e-mail came from, and not their e-mail address.

This is the code I have so far:


my $sendmail = '/usr/lib/sendmail -t';

my $reply_to = "Reply-to: foo\@yahoo.com\n";
my $subject = "Subject: Test E-mail\n";
my $send_to = "To: foo\@yahoo.com\n";
my $from = "From: Tom Jones\n";
my $content = 'Test';

open(SENDMAIL, "|$sendmail") or die "Cannot open sendmail!";
print SENDMAIL $reply_to;
print SENDMAIL $from;
print SENDMAIL $send_to;
print SENDMAIL $subject;
print SENDMAIL "Content-type:text/plain\n\n";
print SENDMAIL $content;

(The names and e-mail addresses above are changed because I don't want spam bots to get the real addresses.) This code causes the e-mail to say it's from Tom.Jones@heroofcamelot.com when it's sent, but I want the name to just say Tom Jones. How do I get that to work?

Not sure if this makes any difference, but I'm on WH 3.0

03-12-2011, 04:30 PM
Try this:

my $from = "From: Tom Jones <tom\@example.com>\n";

03-12-2011, 04:35 PM
P.S. I got rid of the double posting for you. To keep from having the log out issue while composing a post you can choose to have the forum remember you when you log in. Of course that also means that from the computer you do that on, anyone who accesses the forum would be logged in as you because it sets a cookie. If you are not on a secure computer of your own you can simply manually log out when you are done and then the next time you would log back in and choose the option again.

03-12-2011, 05:15 PM
Thanks. That worked. Thanks also for getting rid of the other thread.