CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How Do I Send Mail in either text or html format?

 



sleuth
Enthusiast

Dec 12, 2000, 2:21 PM

Post #1 of 1 (4247 views)
How Do I Send Mail in either text or html format? Can't Post

You Can Use the most common way, by using sendmail which is on most linux/unix based servers, most commonly located at "/usr/lib/sendmail", to find out all of the locations on your linux/unix based server, in Telnet or your Shell, type "whereis sendmail", or run a perl program and use "system("whereis sendmail");"

open(MAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n";
print MAIL <<"EOF";
ReplyTo: "me\@host"
From: "Perl Guru Forums" <me\@host>
To: "Recipient" <you\@otherhost>
Subject: This is the subject.
Body of the message goes here, in as many lines as you like.
EOF
close(MAIL) or warn "sendmail didn't close nicely";

The -oi option prevents sendmail from interpreting a line consisting of a single dot as ``end of message''.
The -t option says to use the headers to decide who to send the message to.
The -odq option says to put the message into the queue. This last option means your message won't be immediately delivered, which is good to use when sending a lot of mail all at once, otherwise, you may want to leave this out.
Another Way to send mail, is to use the CPAN module Mail::Mailer:

use Mail::Mailer;
$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
To => $to_address,
Subject => $subject,
}) or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();

If you wanted to send your mail in HTML format using sendmail, you could add the line "Content-type: text/html" in the body of the message like so:

open(MAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n";
print MAIL <<"EOF";
ReplyTo: "me\@host"
From: "Perl Guru Forums" <me\@host>
To: "Recipient" <you\@otherhost>
Subject: This is the subject.
Content-type: text/html
<p><font face="Verdana" size="2" color="#000080"><b>Your HTML message here.</b></font>
EOF
close(MAIL) or warn "sendmail didn't close nicely";

Sleuth


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives