Thursday, May 28, 2015

Sending mail with HTML content in PERL

Continue with my previous post, here you can find sending an email with HTML content in mail body.

#!/usr/bin/perl
use FileHandle;
my $con_email="out.html";
my $fh = new FileHandle(">$con_email") or die $!;
$fh->print("Content-Type: text/html\n");
$fh->print("<html>");
$fh->print("<body>");
my $to = 'mbcdba@gmail.com';
my $from = 'noautoreply@gmail.com';
my $replyto = 'no_auto_reply@gmail.com';
my $subject = 'Test Email';
my $message = 'Simple <a href="http://mbc-dba.blogspot.in/2015/05/sendmail-utility-sending-mail-in-perl.html">script</a> to sending mail in perl.';
$fh->print("Reply-to: $replyto\n");
$fh->print("To: $to\n");
$fh->print("Cc: $to\n");
$fh->print("From: $from\n");
$fh->print("Subject: $subject \n\n");
$fh->print("$message");
$fh->print("</body>");
$fh->print("</html>");
system("/usr/lib/sendmail -t -oi < $con_email");
print "Email Sent Successfully\n";

Thats it..hope this will help you. Please comment here If you have any queries.

Thanks,
Chowdari 

No comments:

Post a Comment

Some Most Popular Articles