Syntax error Sending an HTML Message using Perl

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 = 'abcd@gmail.com';
$from = 'webmaster@yourdomain.com';
$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

650 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements