1

I have my html code inside my array

   @array //contains all HTML table code

I want to send an e-mail that sends this html code through and converts into the HTML table it is meant to be (not just html code text)

$to = 'my@email.com';
$from = 'my@email.com';
$subject = 'Test';
@message = @array;


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";


}

Right now this sends me an e-mail with all the html code as just lines of code and text, however I want it to convert into the html table as it does normally. I tried using MIME but could not get it to work. Help would be greatly appreciated.

JohnEgg
  • 59
  • 1
  • 1
  • 7
  • What do you mean by "not just HTML code text"? – Matt Jacob Oct 09 '18 at 00:15
  • Possible duplicate of [How to send a html email with the bash command "sendmail"?](https://stackoverflow.com/questions/1333097/how-to-send-a-html-email-with-the-bash-command-sendmail) – Matt Jacob Oct 09 '18 at 00:19
  • Make sure you have not HTML-escaped your HTML. Otherwise, the problem is not how you are sending the text, but how the client is interpreting the body based on your headers. Instead of shelling out to sendmail consider using a module like [Email::Stuffer](https://metacpan.org/pod/Email::Stuffer) which among other things makes it easy to specify HTML contents with html_body (and defaults to using sendmail to send the mail you've constructed). – Grinnz Oct 09 '18 at 00:33
  • @MattJacob What I mean by that is that I do not just want the text to show up, but the table instead. – JohnEgg Oct 09 '18 at 08:19

1 Answers1

2

You ended the header too early.

You effectively have the following:

print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "\n";
print MAIL "Content-type: text/html\n";
print MAIL $html;

You want the following:

print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-type: text/html\n";
print MAIL "\n";
print MAIL $html;
ikegami
  • 367,544
  • 15
  • 269
  • 518