From 709e2d5b62a5eb1301f63d7ca3ff06a27bfe47e0 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Thu, 10 Sep 2026 08:11:24 +0200 Subject: [PATCH] Normalise line breaks in S/MIME signed messages openssl_pkcs7_sign() returns its headers and body with bare LF line breaks. They were copied into the message verbatim, so signed mail was rejected by SMTP servers that enforce RFC 5321 line endings with 550 5.6.11 SMTPSEND.BareLinefeedsAreIllegal. Fixes #3067 --- src/PHPMailer.php | 5 +++-- test/PHPMailer/PHPMailerTest.php | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 8f4188d..547024e 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -3320,8 +3320,9 @@ class PHPMailer @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; - $body = $parts[1]; + //openssl emits bare LF breaks, which SMTP servers may reject + $this->MIMEHeader .= static::normalizeBreaks($parts[0]) . static::$LE . static::$LE; + $body = static::normalizeBreaks($parts[1]); } else { @unlink($signed); throw new Exception(self::lang('signing') . openssl_error_string()); diff --git a/test/PHPMailer/PHPMailerTest.php b/test/PHPMailer/PHPMailerTest.php index 96d22b0..48a6b42 100644 --- a/test/PHPMailer/PHPMailerTest.php +++ b/test/PHPMailer/PHPMailerTest.php @@ -971,6 +971,11 @@ EOT; $msg = $this->Mail->getSentMIMEMessage(); self::assertStringNotContainsString("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers'); + self::assertSame( + 0, + preg_match_all("/(?