当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Pear Mail won't send if From header has scandinavian characters

问题描述:

Imagine the following:

$from = "Testäöå <[email protected]>";

....

$headers = array ('From' => $from,

'To' => $to,

'Subject' => $subject,

'MIME-Version' => "1.0",

'Content-type' => "text/html; charset=iso-8859-1");

If the $from variable is just "Test <[email protected]>", script works fine.

网友答案:

Since you're specifying the headers directly, you need to escape them manually. Only ASCII characters are allowed in headers, so you need to escape them.

You can do that i.e. with

'=?UTF-8?B?'.base64_encode($from).'?='

Alternatively, you can use the Multibyte string functions as described in the comments of http://pear.php.net/manual/en/package.mail.mail.send.php :

$encodedFrom = mb_encode_mimeheader($from, 'UTF-8', 'Q');
分享给朋友:
您可能感兴趣的文章:
随机阅读: