加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

从perl脚本以html格式发送邮件

发布时间:2020-12-16 06:15:31 所属栏目:大数据 来源:网络整理
导读:我正在使用unix环境并有一个perl脚本来发送邮件,但我需要发送 HTML格式的邮件,但它打印,因为它是HTML代码.所以任何人都可以让我知道它如何操纵或编译HTML和发送格式化的邮件. #!/usr/bin/perl#print "Content-type: text/htmlnn";print("enter my name");c
我正在使用unix环境并有一个perl脚本来发送邮件,但我需要发送 HTML格式的邮件,但它打印,因为它是HTML代码.所以任何人都可以让我知道它如何操纵或编译HTML和发送格式化的邮件.

#!/usr/bin/perl
#print "Content-type: text/htmlnn";

print("enter my name");
chop($name=<stdin>);
&mail();


sub mail{

$title='perl';
$to='abcd@acv.com';
$from= 'xyz@xyz.com';
$subject=$name;

open(MAIL,"|/usr/sbin/sendmail -t");

## Mail Header
print MAIL "To: $ton";
print MAIL "From: $fromn";
print MAIL "Subject: $subjectnn";
## Mail Body
print MAIL $name;
print MAIL "<html><body><p>";
print MAIL "<b>Hello</b>";
print MAIL "This is a test message from Cyberciti.biz! You can write your";

print MAIL "</p></body></html>";
##print MAIL "$title";
close(MAIL);
}

它在邮件中打印:

<html><body><p><b>Hello</b>This is a test message from Cyberciti.biz! You can write your</p></body></html>

像这样…因为它似乎没有将其转换为html格式.
所以请帮助我.

解决方法

使用 Mime::Lite.这个例子:

my $msg = MIME::Lite->new(
     To      => 'you@yourhost.com',Subject => 'HTML example',Type    => 'text/html',Data    => '<h1>Hello world!</h1>'
);

$msg->send();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读