我一直在努力解决这个问题,但找不到任何关于我的问题的有用文章。我正在使用内置邮件功能编写一个 PHP 站点,用于快速确认电子邮件。我意识到对内置邮件功能存在相当大的偏见,但到目前为止它对我来说效果很好,我希望能够继续使用它。当我只发送一封纯文本电子邮件时,一切都很好,就好像我只发送一封 HTML 电子邮件一样。但是,如果我尝试发送多部分文本/HTML 电子邮件,则两个版本都会显示在我的电子邮件客户端中(尝试了 Thunderbird 和 gmail)。我希望这里有人可以帮助我找出我做错了什么(除了使用mail()而不是PHPMail)。这是我的代码片段
$uid = md5(uniqid(time()));
$strSubject = "Confirmation for $strEventName on $strEventDate";
$strHTMLMsg = "<h1><center>You are confirmed for the following event:</center></h1><br>\n$strEvenDetails";
$strMsg = strip_tags($strHTMLMsg);
$toEmail = "\"$strName\" <$strEmail>";
$header = "$FromEmail\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= "This is a MIME encoded message.\n\n";
$header .= "--".$uid."\n";
$header .= "Content-type:text/plain; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $strMsg."\n\n";
$header .= "--".$uid."\n";
$header .= "Content-type:text/HTML; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $strHTMLMsg."\n\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: application/ics; name=\"".$strFileName."\"; method=PUBLISH; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= "Content-Disposition: attachment; filename=\"".$strFileName."\"\n\n";
$header .= $strICSEvent."\n\n";
$header .= "--".$uid."\n";
$bSuccess = mail($toEmail,$strSubject,"",$header);