开发者

UTF-8 emails to Mac Mail and Gmail

I'm using Pear mail_mime to send HTML emails out, and first the UTF-8 characters were messed up in Gmail, but not in Mac Mail. I discovered that I needed to add parameters开发者_开发知识库 to the get() function to correct the character set used in the HTML portion of the MIME message. It was defaulting to ISO.

So, I've corrected this problem, the email source looks correct, Gmail is working fine, but now inexplicably Mac Mail is having an issue, despite it working before with the wrong declared character set. I've tried a bunch of different things, including going back to the wrong character set, but Mac Mail still won't render the message properly.

Does anyone have any ideas on what could be causing this?

Here's the code, the HTML is set before this:

$params["host"] = "xxx";
$params["auth"] = true;
$params["username"] = "xxx";
$params["password"] = "xxx";
$params["html_charset"] = "utf-8";
$params["head_charset"] = "utf-8";
$params["text_charset"] = "utf-8";

$text = 'Text version of email';
$crlf = "\n";

$hdrs = array(
        'From'    => 'xxx',
        'Subject' => 'xxx'
        );

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get($params);
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('smtp', $params);
$send = $mail->send($to, $hdrs, $body);
if (PEAR::isError($send)) { print($send->getMessage());} else echo "Mail sent to: $to";


Include Content type and carset in your headers array, something like the following should work, but I havent tested it.

$hdrs = array(
    'From'    => 'xxx',
    'Subject' => 'xxx',
    'Content-Type' => 'text/html',
    'charset' => 'UTF-8',
);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜