I am trying to send an HTML email using Perl.
open(MAIL,"|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "Content-Type: text/html; charset=ISO-8859-1\n\n"
. "<html><head></head><body>@emailBody";
close(MAIL)
Is that the correct way of doing it? It is not working for some reason. Thanks for your help.
Start with Email::Sender::Simple or Email::Sender.
There is a quickstart guide in CPAN, and Ricardo wrote a good use-me in his 2009 advent calendar
From the quickstart guide:
use strict;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => '"Xavier Q. Ample" <[email protected]>',
From => '"Bob Fishman" <[email protected]>',
Subject => "don't forget to *enjoy the sauce*",
'Content-Type' => 'text/html',
],
body => "<p>This message is short, but at least it's cheap.</p>",
);
sendmail($email);
The content type should be part of the mail header. Right now it's part of the mail body. The header is separated from the body by a double newline. So, removing the second newline after the subject header should fix the problem of content type not being correctly interpreted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With