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

Fix DKIM's error when there is S/MIME-sign #2340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,14 @@ public function createBody()
@unlink($signed);
//The message returned by openssl contains both headers and body, so need to split them up
$parts = explode("\n\n", $body, 2);
$this->MIMEHeader .= $parts[0] . static::$LE . static::$LE;
//In $parts[0] there is MIME-Version and Content-Type delimited by "\n".
//Need to separate them, otherwise error with DKIM: "dkim=neutral (body hash did not verify)"
//(The reason is in "h=Date:To:From:Reply-To:Subject:Message-ID:X-Mailer;" without MIME-Version and Content-Type)
$subparts = array_map('trim', explode("\n", $parts[0]));
foreach($subparts as $subpart) {
$this->MIMEHeader .= $subpart . static::$LE;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is great here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a function to normalise breaks in static::normalizeBreaks() which would make for a cleaner implementation here.

$this->MIMEHeader .= static::$LE;
$body = $parts[1];
} else {
@unlink($signed);
Expand Down