【发布时间】:2012-03-04 12:40:36
【问题描述】:
我决定通过他们网站上的一些入门脚本深入研究 perl。我从http://learn.perl.org/examples/email.html 开始尝试一个基本的电子邮件发送脚本。
这是实际代码:
#!/usr/bin/perl
use strict;
use warnings;
#Character encoding var
my $encoding='text/plain; charset="iso-8859-5"';
#Create the message
use Email::MIME;
my $message = Email::MIME->create(
header_str => [
From => 'gmail@gmail.com',
To => 'gmail2@gmail.com',
Subject => 'I sent you this message using Perl.',
],
body_str => 'I sent you this message using Perl. One of those languages that would\' would\'ve been helpful much sooner in my life...',
);
use Email::Sender::Simple qw(sendmail);
sendmail($message);
当我执行perl script.pl 时得到的是一条错误消息
body_str was given, but no charset is defined at /usr/local/share/perl/5.10.1/Email/MIME.pm line 243
Email::MIME::create('Email::MIME', 'header_str', 'ARRAY(0x9a04818)', 'body_str', 'I sent you this message using Perl. One ...') called at script.pl line 10
我在 Email::MIME 模块周围进行了一些搜索,并找到了 body_str 部分,但它并没有说明错误消息。我假设我需要设置编码,但我不确定如何去做。
【问题讨论】:
-
感谢@cjm,示例现已修复,感谢您提出!