下面是我用来发送 HTML 电子邮件的 perl 代码:
#!/usr/bin/perl
use strict;
use warnings;
use Switch;
use IO::File;
my $score = 2;
my $to = 'abc@a.com';
my $from = 'def@b.com';
my $subject = "SHV summary report for servers with score $score or higher";
my $mailbody = '<html><body>Hello</body></html>';
open(MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: text/html; charset=utf-8\n\n"
. "$mailbody";
close(MAIL);
它不工作。我没有收到任何电子邮件。但是,如果我将 open () 调用替换为:
打开(邮件,“|cat -t”);
它打印以下内容:
To: abc@a.com
From: def@b.com
Subject: SHV summary report for servers with score 2 or higher
Content-Type: text/html; charset=utf-8
<html><body>Hello</body></html>
如果我更换:
my $subject = "SHV summary report for servers with score $score or higher";
和:
my $subject = "SHV summary report for servers with core $score";
然后一切正常。如果我
将“core”改回“score”,或
在字符串中添加“或更高”,或
将其更改为“SHV 得分 $score 或更高”
它停止工作。有谁知道为什么?
谢谢,亚历克斯