我有一个运行邮件软件的服务器。此软件使用phpmailer。
如果我通过这个软件发送电子邮件,我没有问题,我会得到SPF=PASSDKIM=PASS
但是,当我尝试使用一个普通的php文件,它只使用mail()时,我得到的电子邮件有一个dkim=softfail (fail, body has been altered) [email protected]错误。具体情况如下。
我在网上查了几个小时,但我发现的都是指向rfc规范的链接,说这个问题是由诸如“超过990字节的行”或“格式错误的行结尾”(这两个都不适用于这里,因为我使用chunk_split())之类的东西引起的。
我的代码中的dkim有什么问题?有没有另一个RFC规范,我正在忽略?

**PHP script I use:**

//build array with headers
$header = array();
$boundary = md5(uniqid(rand()));
$header[] = "MIME-Version: 1.0";
$header[] = "Content-Type: multipart/alternative; boundary = $boundary";
$header[] = "From: Me <[email protected]>";

// get html version
ob_start();
include('html.php');
$Html = ob_get_contents();
ob_end_clean();

// get TXT version
ob_start();
include('txt.php');
$Txt = ob_get_contents();
ob_end_clean();

// Build final message body
// TXT part of message
$body = "--$boundary\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n";
$body .= chunk_split(base64_encode($Txt));

// HTML part of message
$body .= "--$boundary\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n";
$body .= chunk_split(base64_encode($Html));
$body .= "--$boundary--";

// sent email
$isMailed = mail("[email protected]","=?UTF-8?B?".base64_encode($subject)."?=",$body, implode("\n", $header));

编辑:为了帮助解决这个问题,下面是一个示例电子邮件头,我使用上面的脚本得到它:
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from localhost (mx1.example.com [127.0.0.1])
    by mx1.example.com (Postfix) with ESMTP id 4E50FBF31F
    for <[email protected]>; Tue, 16 Dec 2014 16:54:43 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at mx1.example.com
Authentication-Results: mx1.example.com (amavisd-new);
    dkim=softfail (fail, body has been altered) [email protected]
Received: from mx1.example.com ([127.0.0.1])
    by localhost (mx1.example.com [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id o8MXZhIlf1tF for <[email protected]>;
    Tue, 16 Dec 2014 16:54:42 +0100 (CET)
Received: from example.com (example.com [123.23.45.67])
    by mx1.example.com (Postfix) with SMTP id 92A21AF218
    for <[email protected]>; Tue, 16 Dec 2014 16:54:41 +0100 (CET)
Received: from localhost (mailsvr [127.0.0.1])
    by example.com (Postfix) with ESMTP id 895B51018227
    for <[email protected]>; Tue, 16 Dec 2014 16:56:23 +0100 (CET)
X-Virus-Scanned: amavisd-new at example.com
Received: from example.com ([127.0.0.1])
    by localhost (mailsvr.example.com [127.0.0.1]) (amavisd-new, port 10024)
    with LMTP id gm+3YJEGgEc7 for <[email protected]>;
    Tue, 16 Dec 2014 16:56:22 +0100 (CET)
Received: by example.com (Postfix, from userid 47)
    id A973B317802E; Tue, 16 Dec 2014 16:56:20 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=example.com;
    s=default; t=1418745380;
    bh=wL3reSbwXm4SPw5A8n9RooRKg+7j0rkM5+iBCFG51XI=;
    h=To:Subject:MIME-Version:Content-Type:From:Message-Id:Date;
    b=BALRnjP3rx8LcYUxvrLBSASiZyFgA5ckTvGHoKF4V+o8JOLtLTmpmPQS91ohHIwOq
     UFRhv6qJl9ObvFWl0c6QyVthGjCz2+2vB6RkMXQxzJgwxPIe6X51iIEDxA4Y3EYs+x
     0DxmjMTt5tNKNBrjvEtZiEolkfbua8cearxA/Q3M=
To: [email protected]
Subject: =?UTF-8?B?dGVzdA==?=
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary = 47eacbbcbff31a13d0894e4f9ac0450b
From: Me <[email protected]>
Message-Id: <[email protected]>
Date: Tue, 16 Dec 2014 16:56:20 +0100 (CET)

--47eacbbcbff31a13d0894e4f9ac0450b
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64

dGVzdA==
--47eacbbcbff31a13d0894e4f9ac0450b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64

PGh0bWw+PGhlYWQ+PC9oZWFkPg0KPGJvZHk+DQo8cD50ZXN0PC9wPg0KPC9ib2R5Pg0KPC9odG1s
Pg==
--47eacbbcbff31a13d0894e4f9ac0450b--

最佳答案

你的服务器是什么?您使用的是哪种类型的邮件服务器?
任何仍在运行dkim的人都可以切换到opendkim
几分钟后-保留现有密钥、DNS设置,
等。
例如,如果您运行的是centos 6,如果您启用了epel
只需"yum install opendkim"即可安装最新的
具有最常见默认值的opendkim版本
配置,包括服务器的一组默认密钥。这个
OpenDKIM包在Fedora14-17和
海拔5-6。
第二种故障排除方法:
如果您使用\n表示换行符(例如标题行的结尾)。但您必须使用\r\n。这为我解决了问题!

关于php - dkim = softfail与mail()但不是与phpmailer吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27491857/

10-09 08:25