明文/ HTML电子邮件在mac邮件客户端不起作用
问题描述:
下面的代码是我正在使用的代码。它在thunderbird中可以正常工作,但在Mac邮件客户端中却不行(我承担任何由微软制作的东西,我目前无法访问它来测试它)。就像我意识到各种邮件客户端的特质一样,我被这个迷失了!这是相当自我解释,但我试图发送纯文本和HTML电子邮件,以增加读者。任何帮助将非常感激。明文/ HTML电子邮件在mac邮件客户端不起作用
编辑
我应该澄清的是,内容得到不论发送,但在雷鸟它正确地显示消息,但在Mac邮件客户端,你得到的第一个PHP-ALT整个事情到最后PHP
<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
答
与其尝试和推出自己的邮件程序,请尝试PHPMailer。它对multipart/alternative有非常好的支持。整合这一点要比推出自己的解决方案容易得多。我一直在那里 - 在无休止地处理奇怪的MIME问题之后,我放弃了手工制作的邮件,转而采用这种方式,并在我幸免于难的时候专注于其他事情。
换句话说,不要重新发明轮子。虽然自己做这件事可能是一个很好的挑战,如果你只是想让它工作,你会在这个过程中学到很多,这些人已经处理了你的复杂性。
答
你没有正确使用输出缓冲 - 参见手册页ob_end_clean地看到,它不会返回捕获输出,你需要ob_get_contents为:
$message =ob_get_contents();
ob_end_clean();
为此干杯,但唉,我刚刚给它一个镜头,它仍然无法正常工作。 – Drew 2008-12-08 10:01:50
是否有任何东西得到交付?如果是这样,张贴电子邮件的全部来源 – 2008-12-08 10:02:55