我的邮件服务器运行良好,配置了 SPF、DKIM 和反向 DNS。我可以使用类似以下内容将电子邮件发送到 Outlook.com:
echo "This is only a test" | mail username@outlook.com
当我尝试使用同一台服务器通过 PHP 发送电子邮件时出现问题:
$header .= "Return-Path: Some User <mailsender@mydomain.com>\r\n";
$header .= "From: Some User <mailsender@mydomain.com>\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "User-Agent: Some User Mail Sender\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n";
mail("usernama@outlook.com","My title", "Message body", $header);
我尝试使用 appmaildev.com 验证我的邮件,报告显示:
DKIM result: fail (wrong body hash: <*** body hash ***>)
即使出现此错误,Outlook.com 仍表示它通过了 DKIM 验证,但 PHP 邮件功能发送的所有邮件都会进入垃圾文件夹。以下是直接通过 Bash 和 PHP 发送的消息示例:http://pastebin.com/ndXJszic
谁能帮帮我?
谢谢。
编辑 从 header 中删除 \r 后,DKIM 正文哈希错误消失了。但我仍然无法向 Outlook 发送电子邮件...
最佳答案
这可能是权限问题。
您的 Web 服务器通常以不同于您在命令行上使用 mail
时的用户身份运行,因此设置 From:
header 将在传出邮件中创建额外的警告 header 电子邮件。
您可以在服务器上修改名为 /etc/mail/trusted-users
的文件。确保用户 apache
(或您的 php 脚本运行的任何用户)出现在该文件中;如果不是,请添加用户名,然后重新加载 sendmail
。
/etc/mail/trusted-users
的示例内容:
# trusted-users - users that can send mail as others without a warning
# apache, mailman, majordomo, uucp, are good candidates
apache
关于php - 通过 PHP 将 DKIM 签名的电子邮件发送到 Outlook.COM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13595042/