通过PHP发送经DKIM签名的电子邮件到Outlook.COM

10

我的邮件服务器已经配置了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 mail 函数发送的所有邮件都会进入垃圾邮件文件夹。以下是直接通过 Bash 和通过 PHP 发送的邮件示例:http://pastebin.com/ndXJszic 有人能帮我吗?
谢谢。 编辑:从邮件头中删除 \r 后,DKIM 正文哈希错误已消失。但我仍然无法向 Outlook 发送电子邮件...

2
您希望安装SpamAssassin并将您的邮件通过它来查看是否存在任何红旗。DKIM通常无法帮助通过垃圾邮件过滤器。 - Michael Mior
您可能还想尝试向不同的域发送电子邮件。有些域可能会丢弃电子邮件,而其他域可能会接受。 - user968808
还可以查看下面的链接以获取更多想法:http://serverfault.com/questions/505182/configure-postfix-to-dkim-sign-emails-generated-from-the-system - Sanket
4个回答

1

这可能是一个权限问题。

您的Web服务器通常以不同于在命令行上使用mail时的用户身份运行,因此设置From:标头将在发出的电子邮件中创建其他警告标头。

您可以在服务器上修改一个名为/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

1

首先,无法保证电子邮件不会被标记为垃圾邮件,唯一的方法是收件人将发件人地址添加到白名单中。

SPF和DKIM仅用于确保电子邮件来自该域或电子邮件,但不能保证其不是垃圾邮件。

像Outlook.com等其他反垃圾邮件系统会检查许多内容,例如发件人IP地址、每小时从该IP发送的电子邮件数量、电子邮件内容(文本、链接)、声誉等。

在您的示例中,您没有显示正文内容,也许这就是一个电子邮件被标记为垃圾邮件而另一个电子邮件未被标记为垃圾邮件的原因。


认为有一条消息正文:“消息正文” ;) - Chris Pfohl

0

在解决电子邮件传递问题时,我使用25号端口的电子邮件检查。

它会告诉您哪些内容通过/未通过以及SpamAssasin如何对您的消息进行排名。

网址是: http://www.port25.com/support/authentication-center/email-verification/

要直接将结果发送到任何地址,该地址需要添加到check-auth地址中。例如,要将结果发送到: jsmith@yourdomain.com,示例邮件应发送至check-auth-jsmith=yourdomain.com@verifier.port25.com。

使用此功能,您可以找出您的DKIM是否正常工作/已验证以及您的SpamAssasin评分。


0
尝试使用 Pear mail,并在其周围创建一个包装类。我正在与DKIM一起使用它,没有任何问题。我应该提到,我还在使用SpamAssassin(如先前提到的)和ClamAV。
<?php

// Include the Pear Mail header
require_once '/usr/share/php/Mail.php';


class MailWrapper {
    public static function Send($to, $subject, $body) {
        // Email details
        $from = 'No Reply <noreply@yourdomain.com>';
        $server = 'mail.yourdomain.com';
        $port = 25;
        $username = 'sending.account@yourdomain.com';
        $password = 'yourp4ssw0rd';
        // Formalize mail server connection info
        $headers = array('From' => $from,
                 'To' => $to,
                 'Subject' => $subject,
                 'Date' => date('r'),
                 'Return-Path' => $from,
                 'Content-Type' => 'text/html; charset=UTF-8',
                 'Content-Transfer-Encoding' => '7bit',
                 'Mime-Version' => '1.0',
                 'X-Mailer' => 'Your Company (https://yourdomain.com)',
                 'X-Accept-Language' => 'en',
                 'Message-ID' => sha1($body).'@yourdomain.com'
        );
        $connection = array('host' => $server,
                    'auth' => true,
                    'username' => $username,
                    'password' => $password
        );
        // Create the mail server connection 
        $smtp = Mail::factory('smtp', $connection);
        // Send the message
        $mail = $smtp->send($to, $headers, $body);
        // Check for errors
        if (PEAR::isError($mail)) {
            echo '! [email] ['.time().'] Failed sending mail to "'.$to.'"'.PHP_EOL;
            $result = false;
        } else {
            echo '  [email] ['.time().'] Mail sent to "'.$to.'"'.PHP_EOL;
            $result = true;
        }
        return $result;
    }
}

?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接