我正在 HTML 内容类型中使用 PHP mail() 函数发送一封简单的电子邮件。它在每封电子邮件上都能正常工作,但 Outlook 除外,我的邮件的全部内容都会传输到扩展名为 .dat 的附件中。为什么会发生这种情况?有没有办法修复或解决它?
我没有在任何地方找到解释,为什么会在如此简单的情况下发生。 (Outlook 设置设置为以 HTML 方式打开电子邮件,从其他网站发送的 HTML 电子邮件看起来也不错)
mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e5347735f57527e59535f5752105d5153" rel="noreferrer noopener nofollow">[email protected]</a>', "Testing", "First line<br>Second line <b>bolded text</b>", "From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d60745a686f7e6479684d606c6461236e6260" rel="noreferrer noopener nofollow">[email protected]</a>\nContent-Type:".' text/html;charset="UTF-8"'."\nContent-Transfer-Encoding: 8bit");
最佳答案
请注意,“额外的 header 应使用 CRLF (\r\n) 分隔”c.f. https://www.php.net/manual/en/function.mail.php
尝试添加 MIME 标志,看看它是否适合您:
$headers = "From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e5347695b5c4d574a5b7e535f5752105d5153" rel="noreferrer noopener nofollow">[email protected]</a> \r\n".
"Content-type: text/html; charset=UTF-8 \r\n".
"Content-Transfer-Encoding: 8bit \r\n".
"MIME-Version: 1.0";
mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45283c08242c29052228242c296b262a28" rel="noreferrer noopener nofollow">[email protected]</a>', "Testing", "First line<br>Second line <b>bolded text</b>", $headers);
关于php - 为什么 Outlook 电子邮件将我的电子邮件更改为扩展名为 .dat 的附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64315477/