Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dkim fails with Altbody #1352

Closed
NicolasINATIC opened this issue Feb 6, 2018 · 15 comments
Closed

Dkim fails with Altbody #1352

NicolasINATIC opened this issue Feb 6, 2018 · 15 comments

Comments

@NicolasINATIC
Copy link

NicolasINATIC commented Feb 6, 2018

Hi,

When I use phpmailer (6.0.3) without AltBody DKIM pass but when I add AltBody DKIM fail.

Would you know why ?

Best regards,

My code :

<?php
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subject = 'TEST';
$HTMLmessage = '
<html>
	<body>
		<p>
			<b>Message</b> de test en html
		</p>
	</body>
</html>';

$TEXTmessage = 'Message de test en text';
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxxxxxxx'; // Specify main and backup SMTP servers   ns0.ovh.net
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxx'; // SMTP username
$mail->Password = 'xxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // tls sur port 587, ssl sur port 465
$mail->Port = 587; // TCP port to connect to
$mail->From = "xxxxxxxx";
$mail->FromName = "xxxxxxxx";
$mail->AddAddress("xxxxxxxx");
$mail->Subject = $subject;
$mail->IsHTML(TRUE);
$mail->Body = $HTMLmessage;
$mail->AltBody  =  $TEXTmessagetext;            //if I disable this, it pass
$mail->Encoding = "base64";
$mail->DKIM_domain = 'xxxxxxxxx';
$mail->DKIM_private = 'dkim/dkim.private';
$mail->DKIM_selector = 'xxxxxxx';
$mail->DKIM_passphrase = '';
$mail->DKIM_identity = $mail->From;
if(!$mail->Send())
{
        $error_message = "Mailer Error: " . $mail->ErrorInfo;
        echo $error_message;
} else 
{
        $error_message = "Successfully sent!";
        echo $error_message;
}
?>
@NicolasINATIC
Copy link
Author

NicolasINATIC commented Feb 6, 2018

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

$subject = 'TEST';

$HTMLmessage = '
<html>
	<body>
		<p>
			<b>Message</b> de test en html
		</p>
	</body>
</html>';

$TEXTmessage = 'Message de test en text';

$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxxxxxxx'; // Specify main and backup SMTP servers   ns0.ovh.net
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxx'; // SMTP username
$mail->Password = 'xxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // tls sur port 587, ssl sur port 465
$mail->Port = 587; // TCP port to connect to


$mail->From = "xxxxxxxx";
$mail->FromName = "xxxxxxxx";

$mail->AddAddress("xxxxxxxx");
$mail->Subject = $subject;
$mail->IsHTML(TRUE);
$mail->Body = $HTMLmessage;
$mail->AltBody  =  $TEXTmessagetext; //if I disable this, it pass
$mail->Encoding = "base64";

$mail->DKIM_domain = 'xxxxxxxxx';
$mail->DKIM_private = 'dkim/dkim.private';
$mail->DKIM_selector = 'xxxxxxx';
$mail->DKIM_passphrase = '';
$mail->DKIM_identity = $mail->From;


if(!$mail->Send())
{
        $error_message = "Mailer Error: " . $mail->ErrorInfo;
        echo $error_message;
} else 
{
        $error_message = "Successfully sent!";
        echo $error_message;
}

@NicolasINATIC
Copy link
Author

NicolasINATIC commented Feb 6, 2018

When it pass (without altbody) I have :

   MIME-Version: 1.0
   Content-Type: text/html; charset="iso-8859-1"

But with altBody it fail and I have :

   MIME-Version: 1.0 
   Content-Type: multipart/alternative; boundary="b1_rYkK3mYMaouR8CNbl6iNr0wCQqT6psvQpPoqCiJ7XU"

@Synchro
Copy link
Member

Synchro commented Feb 6, 2018

Strange. Those headers are correct – if you have an AltBody, the overall message MIME structure needs to be a multipart/alternative. What is the $headers variable for?

Can you try without $mail->Encoding = "base64";? Base64 CTE isn't really appropriate for text messages; quoted-printable is usually better, and it may be interfering with the DKIM too.

@NicolasINATIC
Copy link
Author

I test without $header variable and without Encoding or with quoted-printable but it always fail.

@NicolasINATIC
Copy link
Author

Thank you for helping me, do you have another idea ?

@zdenekvecera
Copy link
Contributor

zdenekvecera commented Aug 15, 2018

Hello @Synchro , I have the same problem on one server.

$phpMailer = new PHPMailer();
$phpMailer->setFrom('XXX');
$phpMailer->addAddress('XXX');
$phpMailer->Body    = 'Test';
$phpMailer->AltBody = 'Test';
$phpMailer->Subject='Bar';

$phpMailer->DKIM_domain='XXX';
$phpMailer->DKIM_private='XXX';
$phpMailer->DKIM_selector='XXX';
$phpMailer->DKIM_identity='XXX';
$phpMailer->DKIM_passphrase='';

//Suppress listing signed header fields in signature, defaults to true for debugging purpose
//$phpMailer->DKIM_copyHeaderFields = false;
//Optionally you can add extra headers for signing to meet special requirements
//$phpMailer->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];

if (!$phpMailer->send()) {
    echo "Mailer Error: " . $phpMailer->ErrorInfo;
} else {
    echo "Message sent!";
}

Validation of the above code on DKIM is fail.

If I set as an empty string $phpMailer->AltBody = ''; validation is a pass.

I have a problem only on one server, on the other not (they have different configurations).

I tried setting DKIM_copyHeaderFields to true / false, but it did not help.

Similarly, the presence of DKIM_extraHeaders did not help.

I'm testing on the released version 6.0.5 and on the current Master.

Is it possible that this may cause updating the post server (Postfix) or something? Any version about June this year? Because everything worked at the beginning of the year.

Do you have any idea where can be a problem please?

Thanks!

@Maikuolan
Copy link

@zdenekvecera : Just a passing thought (I could be completely off-base here), but are you using Gmail to send emails by any chance? I've seen some weird, unexpected behaviour there before, which sometimes needed outbound emails to be formed in non-recommended or non-standard ways in order to work properly in some weird cases. (Not having a go at Gmail here of course.. I actually use Gmail myself, have done so for many years, and I like their service.. but just sharing it as a possible idea, as it is something I've encountered before).

@zdenekvecera
Copy link
Contributor

zdenekvecera commented Aug 15, 2018

Addition to this post #1352 (comment):

Headers (returned by site http:https://www.appmaildev.com/en/dkim):

Report-Id: 3ebf0431
Sender: [email protected]
Source-IP: 91.239.201.28
Validator-Version: 1.05
x-sender: [email protected]
x-receiver: [email protected]
Received: from replikant73.thinline.cz ([91.239.201.28]) by appmaildev.com with Microsoft SMTPSVC(8.5.9600.16384);
	 Wed, 15 Aug 2018 12:31:42 +0000
Received: by replikant73.thinline.cz (Postfix, from userid 1051)
	id 83894A65; Wed, 15 Aug 2018 14:31:41 +0200 (CEST)
Authentication-Results: replikant73.thinline.cz;
	dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ukazweb.cz [email protected] header.b="KPogShJr";
	dkim-atps=neutral
Date: Wed, 15 Aug 2018 14:31:40 +0200
From: =?utf-8?Q?Laser_Ar=C3=A9na_Kom=C3=A1rno?= <[email protected]>
Reply-To: =?utf-8?Q?Laser_Ar=C3=A9na_Kom=C3=A1rno?= <[email protected]>
To: "[email protected]" <[email protected]>
Message-ID: <wpC6yNW4mnWMBTcQ8nhn3oyDLqOC3z27P4maS1wvE@admin.rezervacnisystemprolaserareny.cz>
Subject: Test
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary=b1_wpC6yNW4mnWMBTcQ8nhn3oyDLqOC3z27P4maS1wvE
Content-Transfer-Encoding: 7bit
X-PHP-Originating-Script: 1051:PHPMailer.php
X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; l=301;
 s=rezervacnisystemprolaserarenycz; t=1534336300; c=relaxed/simple;
 h=From:To:Date:Subject; d=ukazweb.cz; [email protected];
 z=From:=20=3D?utf-8?Q?Laser_Ar=3DC3=3DA9na_Kom=3DC3=3DA1rno?=3D=20<[email protected]>
 |To:=20"[email protected]"=20<[email protected]>
 |Date:=20Wed,=2015=20Aug=202018=2014:31:40=20+0200 |Subject:=20Test;
 bh=s7j4Gf5Us+q/pv4uMWq434BONFLt4npE0s9Jcjb/4jw=;
 b=KPogShJrtAuryF6pKHL/8+iYwS6yGAfdS055napA4Xxh3zwerrLxVo5AOh7VasXDSicNZ0l5qB7idMjT5+YEiETqV4Jj6oig9yTFqEMgSKyUWfpsPqzTSznXUmewQI4MNTYh/t5aXafQZ7C6AY/hsm3mxgy6+YgdmjtakV5iJNw3cbvnGbP7UoaaWK8pKtBMzoaGYgvgG23lkNL2LbIyyfZT1M6vhmZSGSyDAoUoFlYgYm9md6QSEapnd2LcV5B7hCVcpekSB4mvKueOixegXy+gfIpJXsSii9+g6b8bwTuI6REx60YFa7sLXR0QqbVoxSTUs7BzN9DPCJwcooLrhA==
X-Thin-Control-Number: 1051
Return-Path: [email protected]
X-OriginalArrivalTime: 15 Aug 2018 12:31:43.0072 (UTC) FILETIME=[EC599E00:01D43493]

DKIM fail:

DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; l=301;
 s=rezervacnisystemprolaserarenycz; t=1534336300; c=relaxed/simple;
 h=From:To:Date:Subject; d=ukazweb.cz; [email protected];
 z=From:=20=3D?utf-8?Q?Laser_Ar=3DC3=3DA9na_Kom=3DC3=3DA1rno?=3D=20&lt;[email protected]&gt;
 |To:=20"[email protected]"=20&lt;[email protected]&gt;
 |Date:=20Wed,=2015=20Aug=202018=2014:31:40=20+0200 |Subject:=20Test;
 bh=s7j4Gf5Us+q/pv4uMWq434BONFLt4npE0s9Jcjb/4jw=;
 b=KPogShJrtAuryF6pKHL/8+iYwS6yGAfdS055napA4Xxh3zwerrLxVo5AOh7VasXDSicNZ0l5qB7idMjT5+YEiETqV4Jj6oig9yTFqEMgSKyUWfpsPqzTSznXUmewQI4MNTYh/t5aXafQZ7C6AY/hsm3mxgy6+YgdmjtakV5iJNw3cbvnGbP7UoaaWK8pKtBMzoaGYgvgG23lkNL2LbIyyfZT1M6vhmZSGSyDAoUoFlYgYm9md6QSEapnd2LcV5B7hCVcpekSB4mvKueOixegXy+gfIpJXsSii9+g6b8bwTuI6REx60YFa7sLXR0QqbVoxSTUs7BzN9DPCJwcooLrhA==
Signed-by: [email protected]
Expected-Body-Hash: x9Dt+TwVsQ/X4vr0oSXyH2qg5Qf6gm78pw53XRXBV8M=

DKIM-Result: fail (wrong body hash: s7j4Gf5Us+q/pv4uMWq434BONFLt4npE0s9Jcjb/4jw=)

@zdenekvecera
Copy link
Contributor

@Maikuolan: I'm sorry but I do not use Gmail for sending.

@zdenekvecera
Copy link
Contributor

zdenekvecera commented Aug 15, 2018

When I set a empty $mail->AltBody = '';

Headers (returned by site http:https://www.appmaildev.com/en/dkim):

Report-Id: 85c4fe00
Sender: [email protected]
Source-IP: 91.239.201.28
Validator-Version: 1.05
x-sender: [email protected]
x-receiver: [email protected]
Received: from replikant73.thinline.cz ([91.239.201.28]) by appmaildev.com with Microsoft SMTPSVC(8.5.9600.16384);
	 Wed, 15 Aug 2018 12:39:38 +0000
Received: by replikant73.thinline.cz (Postfix, from userid 1051)
	id 82E908E7; Wed, 15 Aug 2018 14:39:37 +0200 (CEST)
Authentication-Results: replikant73.thinline.cz;
	dkim=pass (2048-bit key; unprotected) header.d=ukazweb.cz [email protected] header.b="puqI/c1y";
	dkim-atps=neutral
Date: Wed, 15 Aug 2018 14:39:36 +0200
From: =?utf-8?Q?Laser_Ar=C3=A9na_Kom=C3=A1rno?= <[email protected]>
Reply-To: =?utf-8?Q?Laser_Ar=C3=A9na_Kom=C3=A1rno?= <[email protected]>
To: "[email protected]" <[email protected]>
Message-ID: <Adl57cwNi6XLrD5FkXnS9VqfsRGFDsgIx2jZfnvZs@admin.rezervacnisystemprolaserareny.cz>
Subject: Test
Mime-Version: 1.0
Content-Type: text/html;
 charset=utf-8
Content-Transfer-Encoding: 7bit
X-PHP-Originating-Script: 1051:PHPMailer.php
X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; l=6;
 s=rezervacnisystemprolaserarenycz; t=1534336776; c=relaxed/simple;
 h=From:To:Date:Subject; d=ukazweb.cz; [email protected];
 z=From:=20=3D?utf-8?Q?Laser_Ar=3DC3=3DA9na_Kom=3DC3=3DA1rno?=3D=20<[email protected]>
 |To:=20"[email protected]"=20<[email protected]>
 |Date:=20Wed,=2015=20Aug=202018=2014:39:36=20+0200 |Subject:=20Test;
 bh=fdkeB/A0FkbVP2k4J4pNPoeWH6vqBm9+b0C3OY87Cw8=;
 b=puqI/c1yDDWE1AFnNqeBQzcoIS3KyiOlyCFZ06wrQbFzFE2xg/JFDZpk47B9zg71CRXEFmHAt2jHRV+MWdCfBWJUfTcqtXnTYnYVLNPtCqU+32ZLYiRiABeCC+OFCSoymwWVSTI0aok8hDXlxw+xSTi8D96CiIICxwD3geHHr7AN9WYS6XNa9SZPBwtff2VcJIs/geTeoSA2DsBuwBU6CoexcXBG6+f+kEzxNP31nKA8ZNNZP5dFpHYJzoGoWWDk4ma41Zx56gD6/ORtIyrJXvyQdssWe2JMxVLGglf8HqHFiaKNggeG7HByWikqqWeVZjkt39cuODxdQy9mEL2odg==
X-Thin-Control-Number: 1051
Return-Path: [email protected]
X-OriginalArrivalTime: 15 Aug 2018 12:39:38.0986 (UTC) FILETIME=[080454A0:01D43495]

DKIM pass:

DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; l=6;
 s=rezervacnisystemprolaserarenycz; t=1534336776; c=relaxed/simple;
 h=From:To:Date:Subject; d=ukazweb.cz; [email protected];
 z=From:=20=3D?utf-8?Q?Laser_Ar=3DC3=3DA9na_Kom=3DC3=3DA1rno?=3D=20&lt;[email protected]&gt;
 |To:=20"[email protected]"=20&lt;[email protected]&gt;
 |Date:=20Wed,=2015=20Aug=202018=2014:39:36=20+0200 |Subject:=20Test;
 bh=fdkeB/A0FkbVP2k4J4pNPoeWH6vqBm9+b0C3OY87Cw8=;
 b=puqI/c1yDDWE1AFnNqeBQzcoIS3KyiOlyCFZ06wrQbFzFE2xg/JFDZpk47B9zg71CRXEFmHAt2jHRV+MWdCfBWJUfTcqtXnTYnYVLNPtCqU+32ZLYiRiABeCC+OFCSoymwWVSTI0aok8hDXlxw+xSTi8D96CiIICxwD3geHHr7AN9WYS6XNa9SZPBwtff2VcJIs/geTeoSA2DsBuwBU6CoexcXBG6+f+kEzxNP31nKA8ZNNZP5dFpHYJzoGoWWDk4ma41Zx56gD6/ORtIyrJXvyQdssWe2JMxVLGglf8HqHFiaKNggeG7HByWikqqWeVZjkt39cuODxdQy9mEL2odg==
Signed-by: [email protected]
Expected-Body-Hash: fdkeB/A0FkbVP2k4J4pNPoeWH6vqBm9+b0C3OY87Cw8=
Public-Key: v=DKIM1; h=sha256; t=s; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5AcTJrW00qfCQJKCrntWIQHn/xXbibc2nCygOse9RI+UPKTZe7hH3VI/e8zOidJgSitdN14PFETPOGKGFcVcH8oc9RBZ+cUB8igJKbVhFJVa5ixiuyIWZlWPhjS3fsnAoAqQ7053JbrzgtnHCFc7eS1h4+lJO6mfyvwXaQYqz5sDjiOjCqXA0sF94Ef5R/LsKMwJAJqODo4rGaD0BNLN9+o1x4wNpRv/1r8MJEquZU3Xxp/faf3RYWVwIERrX4wl8drBFclpU2uO0aYXya3RudDi97QDdAR72xO4kz49gsG45g9MtN3V2AZ6hSN43rHHZIgzw3iztSVzpdaP6lQPswIDAQAB;

DKIM-Result: pass

@Maikuolan
Copy link

Hm, okay. It was an idea, anyhow. Must be something else then. :-)

@QRMarketing
Copy link

QRMarketing commented Sep 5, 2018

As an FYI, I have the same issue. Nothing more to add however. Just want to stay informed if a fix every comes. I can be a tester if you want. Thanks in advance. Just can't use DKIM and AltBody.

@oom-
Copy link

oom- commented Aug 2, 2020

I'm using the version '6.1.7', still the same problem. Doesn't works if there is an AltBody, To not add a text version of the body lower the score of the email :/

@firemat
Copy link

firemat commented Apr 17, 2022

Same issue with 6.6.0. When I add an AltBody, the DKIM check fails.

@colinp8
Copy link

colinp8 commented Oct 19, 2022

I was also suffering from this problem. I finally found a solution - at some point, the "mime preamble" was being removed from my messages - either by my outgoing mail server or the receiving ones, who knows.

My fix was to remove the mime preamble from ever entering the message in the first place.

        //Use this as a preamble in all multipart message types
        $mimepre = 'This is a multi-part message in MIME format.' . static::$LE . static::$LE;

change to:

        //(Don't) use this as a preamble in all multipart message types
        $mimepre = '';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants