简体   繁体   中英

dkim=softfail with mail() but not with phpmailer?

I have a server that runs a mailing software. This software uses phpmailer. If I send out an email through this software I have no problem, I get SPF=PASS as well as DKIM=PASS .

However, when I try to use a regular PHP file that just uses mail() , I get the email with a dkim=softfail (fail, body has been altered) header.i=@example.com error. Below are the specifics.

I checked online for hours now, but all I found were links to the RFC specifications, saying that this problem is caused by such things as "Lines longer than 990 bytes" or "Malformated line endings" (both of which do not apply here, as I use chunk_split() ).

What could cause this problem with DKIM in my code? Is there another RFC spec that I am overlooking?

**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 <me@example.com>";

// 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("me@example.com","=?UTF-8?B?".base64_encode($subject)."?=",$body, implode("\n", $header));

EDIT: to help resolve this, here is a sample Email Header that I get with the above script:

Return-Path: <apache@example.com>
Delivered-To: me@example.com
Received: from localhost (mx1.example.com [127.0.0.1])
    by mx1.example.com (Postfix) with ESMTP id 4E50FBF31F
    for <me@example.com>; 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) header.i=@example.com
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 <me@example.com>;
    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 <me@example.com>; 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 <me@example.com>; 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 <me@example.com>;
    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: me@example.com
Subject: =?UTF-8?B?dGVzdA==?=
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary = 47eacbbcbff31a13d0894e4f9ac0450b
From: Me <me@example.com>
Message-Id: <20141216155620.A972B387802D@example.com>
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--

What is your Server? what type of mail server are you using?

Anyone who is still running dkim-milter can swap over to OpenDKIM in a matter of minutes - keeping your existing keys, DNS settings, etc.

If you're running CentOS 6 for example, if you have EPEL enabled you can just do "yum install opendkim" and it will install the latest release version of OpenDKIM with the most common default configuration, including a set of default keys for your server. The opendkim package is available in the stable repos for Fedora 14-17 and EL 5-6.

Second method of troubleshooting: if you're using \\n for newline (example end of header line). But you have to use \\r\\n. This solved it for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM