开发者

Chinese Characters in email sent via PHP not showing up

I send mail via PHP with Chinese characters from my testing server, and it sends it out perfectly. The encoding is UTF-8. When I upload the same PHP file to another server and try to send e-mail from there, it will look 90% fine in one mail client (web-based mail actually, GMail), but in another mail client (Apple Mail) it's all gibberish - even when I try changing the encoding in the mail client.

I'm stuck here, because everything works fine on one server but not another. I'm not sure where to start looking for solutions. What's even more puzzling is that on the production server, the e-mail looks somewhat ok (strange case of some characters not showing), but in other mail apps it looks like garbage.

Any idea where I can start looking to solve this?

PHP

$books = json_decode ($_POST['books']);

$body = '
<body bgcolor="#999999"><center>
<table width="700" border="0" cellspacing="2" cellpadding="10" bgcolor="#FFFFFF">
<tr>
    <td>
    你好 ' . $_POST['name'] . ',<br/><br/>以下是你从学习网站,给孩子讲故事课程,所要求的书籍名单<br/><br/><hr noshade="noshade" />
    </td>
</tr>
<tr>
<td>';

$iLen = count($books);
for ($i = 0; $i < $iLen; $i = $i + 1) {
    $book = $books[$i];

    $body .= '<b>' . $book->title . '</b><br/>' . $book->author . '<br/><br/>';
    $body .= '简介: ' . $book->synopsis . '<br/>';
    $body .= '年龄层: ' . $book->age . '<br/>';
    $body .= '场景: ' . $book->setting . '<br/>';
    $body .= '目的: ' . $book->purpose . '<br/>';
    $body .= '索书号: ' . $book->call . '<br/><br/>';
    $body .= '出版商: ' . $book->publisher . '<br/><br/><hr noshade="noshade" />';

}

$body .= '
</td>
</tr>
<tr>
    <td>
    亲切问侯,<br/>Name
    </td>
</tr>
</table>
</center>
</body>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: Name <no-reply@here.com>' . "\r\n";

$ok = mail ($_POST['email'], '讲故事给孩子听:您所要求的故事精选书单', $body, $headers);

R开发者_如何学Cesult

ä∏ å¥∏ ryan,

ä»¥ä¸—æ˘¯ä∏ ä»⁄å–œä’ ç∏Œç«˙,ç»˙å–©å–∆è®”æ∑亗è¯≤稗,æ≈•èœ™æ±≠ç˚≥䒜籟å∆ŸåŸ

瑲瑲æ√Œæ˛≈å¤˚ç√±ä∏ 
麜å∑—å¸∞é˝·å°π, å±±å§∫ 

Synopsis: 粗å∂¯ç√±ç˚≥å°∂å∑‰å®ˇå®ˇæ•⁄ä’√牨å®∞ç—¬ç≈’ç˚≥戒åπ∂å‚‘å∑‰åœ√åœ√说å®∞æ˛≈å¤˚ç√±å®∞ã•≠
Age Group: 4 - 6 å”™
Setting: ç≤¤ä∏„
Purpose: ä»·å•πè§≠å‚‘ä¿∞è¿˝äº”å–∆ç˚≥æ≥ƒæ∞∑
Call no: JP MAC

Publisher: 麜å∑—å¸∞é˝·å°π, å±±å§∫. 瑲瑲æ√Œæ˛≈å¤˚ç√±ä∏ .丅海 : 尌咴å≥¿ç«¥åΩºç≈√ç¤≤, 2005.


maybe you should encode your message in MIME format


Are the values of "default_charset" in the php.ini both utf8?

That might be able to cause the problem you're seeing. It seems you are relying on the php interpreter to know that the script is written in utf-8, as your passing literal utf-8 characters in the script to the email, and the charset is in the headers is set to utf-8 (which is good).


Is you email multi-part of with plain text and html? Or only html? If it is the former, set the content type of the plain text to utf-8 too.

If it is html alone, you might write a full html with content-type specified inside.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜