【问题标题】:Perl utf8 decode and encodePerl utf8 解码和编码
【发布时间】:2013-11-12 23:29:37
【问题描述】:

我在这里遇到了一种情况,尝试使用来自 Perl(西里尔文)的 Mail::Sendmail 发送和发送电子邮件。

use Mail::Sendmail;
use Encode;
use utf8;

my $subject= "cyrillic message";
....

问题是我在邮件中收到无法识别的符号。

我已经尝试使用 utf8,不使用 utf8,我尝试过 decode 和 encode,decode_utf8 等等(已经阅读了很多,包括 Perlmonks 的讨论),但我仍然收到 2 种无法识别的符号邮件的主题或“子程序条目中的宽字符”。

添加:

#!/usr/bin/perl

use Mail::Sendmail;
use Encode;
use utf8;
use warnings;

my $subject= "cyrillic subject";
my $message= "cyrillic message";


my %mail = (
        To      => 'recipient@example.com',
        Subject => "$subject",
        From    => 'from@example.com',
        Message => "$message",
       );

sendmail(%mail) or die $Mail::Sendmail::error;

print "OK. Log says:\n", $Mail::Sendmail::log;

【问题讨论】:

  • 您能否将错误日志和电子邮件中的文本与use warning; 通过命令行运行时提供的任何警告一起发布。
  • 请提供实际演示问题的代码!
  • 至于use utf8;:如果您的源文件使用UTF-8编码,请使用use utf8;。如果您的源文件使用 US-ASCII 编码,请不要使用 use utf8;
  • 如果我使用 utf8,我会收到“/usr/local/share/perl5/Mail/Sendmail.pm 第 237 行的子例程条目中的宽字符”。如果没有,则发送消息,并且我得到了这个“ÑообÑение”。我也尝试使用 Encode 对其进行编码。

标签: perl decode encode


【解决方案1】:

不使用 utf8 和不使用 Encode 的问题解决了。

我添加了 'Content-type' => 'text/html; charset="utf-8"' 标头,一切都变好了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    相关资源
    最近更新 更多