php - 为什么 Outlook 电子邮件将我的电子邮件更改为扩展名为 .dat 的附件?

标签 php html email

我正在 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/

相关文章:

php - 持久连接应该如何与 PHP 的 PECL Memcached 插件一起使用?

php - 如何将此 PHP 正则表达式转换为 Javascript?

javascript - Angular 4 : How to get index of selected value in a datalist

html - 搜索按钮未与搜索字段对齐

node.js - 如何使用nodemailer正确发送 session 请求?

email - 在 MS Outlook 中组织电子邮件的最佳方式是什么?

javascript - 在没有轮询器的情况下基于 MySQL 数据库创建 Node.js 仪表板

php - 是否可以为其他地方托管的另一个网站托管数据库?

c# - 如何通过 CSharp 以编程方式设置输入元素的值?

google-app-engine - 如何根据 App Engine 中的电子邮件地址确定 user_id?