doushan2224 2013-03-21 21:19
浏览 122
已采纳

非常简单的HTML /纯文本电子邮件在microsoft live.com中根本没有显示

I have been using a very simple PHP function to construct HTML / plain-text emails. It worked well in gmail and many other clients I saw.

As it turns out, @live.com accounts don't get to see the email content at all.

Here's the relevant code:

$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with 

$headers = "From: server@example.com
Reply-To: server@example.com
";
$headers .= "MIME-Version: 1.0
";
//add boundary string and mime type specification
$headers .= "Content-Type: multipart/alternative; boundary=$random_hash
";
$headers .= "Content-Transfer-Encoding: 7bit
";
//define the body of the message.
$message = "This is a MIME encoded message.

" .
    "--$random_hash
" .
    "Content-Type: text/plain; charset=utf-8
" .
    //"Content-Transfer-Encoding: 7bit
" .
"
this is plain text.

" .
"--$random_hash
" .
"Content-Type: text/html; charset=utf-8
" .
    //"Content-Transfer-Encoding: 7bit
" .
    "
<html><body>this is wonderful <b>HTML</b> text.</body></html>" .
    "

--$random_hash--
";
mail('someAddress@live.com', 'This is u umlaut: ü', $message, $headers);

If I only send either HTML or plain-text, it will display properly.

Any ideas?

I do not want to use an extra library. All I need the HTML for is links, basically. The answers on PHP Multi-Part Text/HTML showing blank don't help me.

And btw: the u umlaut is displayed incorrectly in the email list in the live.com inbox but displayed correctly when I open the email in live.com...

  • 写回答

1条回答 默认 最新

  • dongpengyu1363 2013-03-22 11:57
    关注

    Got it after a few hours.

    The issue are the CR and LF.

    I replaced all CRLF ( ) by LF ( ) and it worked.

    On the way, I also replaced 7bit by 8bit.

    And as for the subject line, that was an easy one to google for, and this is the solution for utf-8:

    $subject = '=?utf-8?B?' . base64_encode($subject) . '?=';
    

    Thanks guys!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘