How do I send html email from Perl?
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
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Linux send email from console
- Sending mail with Perl mail script
- Postfix setup catch-all email accounts using /etc/postfix/virtual
- Howto find out perl version
- Email multiple file attachment from Solairs / AIX / HP-UX UNIX/ Linux command line
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: apache web, cgi perl program, cpan module, easy task, email attachments, graphics file, html emails, low calorie, mime, perl script, root user, script code, sending html email, unix linux, use strict, usr bin



June 12th, 2007 at 8:33 pm
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!