Sending an HTML Message Using Perl



If you want to send HTML formatted email using sendmail, then you simply need to add Content-type: text/html\n in the header part of the email as follows −

#!/usr/bin/perl
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Test Email';
$message = '<h1>This is test email sent by Perl Script</h1>';
open(MAIL, "|/usr/sbin/sendmail -t");
# Email Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n";
# Email Body
print MAIL $message;
close(MAIL);
print "Email Sent Successfully\n";
Updated on: 2019-11-29T12:14:02+05:30

603 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements