how to send html email from perl

E

Eric Osman

I just had the same question, and found that the following works.

If you're using the "sendmail" package (see
http://ls6-www.cs.uni-dortmund.de/c...|CPAN|wait|/services/www-db/WAIT/DB/cpan|4120
)

Here's an example of sending an html message. NOTE: To actually use
this example, you will need to change the following things:

1) The first two lines might need to be swapped or otherwise modified
according to what your web server and perl require at the beginning of
perl scripts.
2) The "to" line needs to be edited to show who you're actually sending
the email to.
3) The "smtp" line needs to be changed to contain an outgoing mail
server that you are allowed to use.

ok here's the example:

#!perl
#!/usr/bin/perl
# Example of using sendmail to send html. Author: Eric Osman June 2003
use strict;
use CGI qw:)cgi);
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
my $msg = "";
$msg .= "here's some <b>boldface</b> to prove that html is being sent<br>";
$msg .= "a second line<br>";
my %mail = ( From => '(e-mail address removed)',
To => '(e-mail address removed)',
Subject => "some simple html",
Message => "$msg",
Smtp => 'smtp.cn.com',
'Content-type' => 'text/html; charset="iso-8859-1"'
);
sendmail(%mail) || die $Mail::Sendmail::error;
print "Content-type: text/html\n\n";
print "your html email has been sent";

Enjoy.

/Eric

From: Mark A. Hershberger ([email protected])
Subject: Re: Perl, HTML to Sendmail...

View this article only
Newsgroups: comp.lang.perl.misc
Date: 1999/09/28

[mailed and posted]

Myriad said:
Hello, I'm looking for info on how to recode my Perl script to send HTML
enabled mail via Sendmail. Can anyone help?

(Strange, I had a user ask me the same question today. Perhaps you
are one and the same.)

Find the MIME-tools package on CPAN (or, if you need a URL:
http://www.cpan.org/modules/by-module/MIME) and install it. In the
tar package, look at examples/mimesend for an example of how to send
html mail.

Also, please give users the option to get plain text email instead of
HTML mail. HTML mail can be annoying.

Hope that helps,

Mark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top