About Linux FAQ

Browse More FAQs:

How do I send html email from Perl?

Posted by Vivek Gite [Last updated: November 29, 2007]

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:

Discussion on This FAQ

  1. Frank Wiles Says:

    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!

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!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.