Perl-如何将HTML代码文本转换为电子邮件中的HTML表

时间:2018-10-09 00:04:18

标签: html perl

我的数组中有html代码

   @array //contains all HTML table code

我想发送一封电子邮件,通过它发送此html代码并将其转换为HTML表(不仅仅是html代码文本)

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


}

现在,这会向我发送一封电子邮件,其中包含所有html代码,只是代码行和文本行,但是我希望它像通常一样转换为html表。我尝试使用MIME,但无法正常工作。帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您过早结束标题。

您实际上拥有以下条件:

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;

您需要以下内容:

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;