Q. How Can I send html email from cgi perl program under UNIX / Linux and Apache web sever?
A. Sending HTML email is an easy task with MIME::Lite CPAN module. It is a low-calorie MIME generator.
It can be use to send html emails, graphics file email attachments as a single-part or multi-part message. Here is simple perl script that sends html email.
Install Perl MIME::Lite
If you do not have MIME::Lite module, install using following command (login as a root user):
# cpan -i MIME::Lite
Perl script code
Script to send html email from perl:
#!/usr/bin/perl -w use strict; use MIME::Lite; # SendTo email id my $email = 'user@somewhere.com'; # create a new MIME Lite based email my $msg = MIME::Lite->new ( Subject => "HTML email test", From => 'YOU@somewhere.com', To => $email, Type => 'text/html', Data => '<H1>Hello</H1><br>This is a test email. Please visit our site <a href="http://cyberciti.biz/">online</a><hr>' ); $msg->send();
Save the script and execute it. Here is an email (sample) send by above script:
Read man page of MIME::Lite for more information:
perldoc MIME::Lite
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 11-29-07

{ 2 comments… read them below or add one }
If you’re interested in sending HTML emails from Perl you might want to check out an article I wrote on MIME::Lite::TT and MIME::Lite::TT::HTML for sending Emails.
By using the MIME::Lite::TT and/or MIME::Lite:TT::HTML modules you can take advantage of both the features of MIME::Lite, but also add in the ability to use Template Toolkit templates for your text/plain and text/html parts.
Hope it helps!
Thanks Frank. Great tuturial.