2

我希望能够使用包含 8 位字符 åäö 的 PHP mail() 发送电子邮件。它们将用于主题、消息和“发件人:”标题中。在不使用 PEAR 包的情况下如何做到这一点?

4

3 回答 3

4

如果您不介意对不需要的单词进行编码,最简单的解决方案是将所有内容放在 base64 RFC 2047 编码字中:

$subject= "=?utf-8?b?".base64_encode($subject)."?=";
$body= "blah blah $utf8text blah";
$headers= "MIME-Version: 1.0\r\n";
$headers.= "From: =?utf-8?b?".base64_encode($fromname)."?= <$fromaddress>\r\n";
$headers.= "Content-Type: text/plain;charset=utf-8";

mail($toaddress, $subject, $body, $headers);
于 2009-09-30T21:25:15.023 回答
0

使用 swiftmailer 库。http://swiftmailer.org/

于 2010-07-12T08:34:54.477 回答
-2
$headers = array('From' => $from,
    'To' => "<$to>",
    'Subject' => $subject);

if ($is_html) {
    $headers['Content-type'] = "text/html; charset=UTF-8";
} else {
    $headers['Content-type'] = "text/plain; charset=UTF-8";
}

这对我有用

于 2012-02-29T08:58:15.920 回答