Blnukem Blnukem - 6 months ago 12
Perl Question

Why do I get 'syntax error at Email/MIME/CreateHTML.pm line 203, near "croak "You must supply a body""' when I use Email::MIME::CreateHTML?

I'm using the CPAN module Email::MIME::CreateHTML but keep getting the following error:


syntax error at Email/MIME/CreateHTML.pm line 203, near "croak "You must supply a body""


Here's my script:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

use Email::Sender::Transport::SMTPS;
use Email::MIME::CreateHTML;

my $SendTo = 'MyEmail@SendTo.com';
my $SendFrom = 'MyEmail@SendFrom.com';
my $Subject = 'test MSG';

my $SMTP_Server = 'smtp.gmail.com';
my $SMTP_SSL = 'starttls';
my $SMTP_Port = 587;
my $SMTP_User = 'my@gmail.com';
my $SMTP_Password = 'MyGmailPassword';

my $eMailMessage = "Test MSG";

use Email::Sender::Transport::SMTPS;
use Email::MIME::CreateHTML;

my $transport = Email::Sender::Transport::SMTPS->new({
host => $SMTP_Server,
ssl => $SMTP_SSL,
port => $SMTP_Port,
sasl_username => $SMTP_User,
sasl_password => $SMTP_Password,
debug => 1,
});


my $email = Email::MIME->create_html(
header => [
To => $SendTo,
From => $SendFrom,
Subject => $Subject,
],

body => $eMailMessage

);

sendmail($email, { transport => $transport });

print 'Mail Sent';


How can I fix this?

Answer

You must have an old version of Email::MIME::CreateHTML. This looks like a bug that was fixed in version 1.030:

This happens because the create_html method being mixed into Email::MIME does not have croak in scope. The fix is to simply explicitly load Carp again after the package Email::MIME declaration.

I'm not sure exactly how this ever worked, honestly.

Upgrade to the latest version.