#3078·PHPMailer

Headers of signed S/Mime email is not well formated

Author: panoma-berlinCreated Jul 26, 2024Updated Sep 10, 2026

If I sign an email with S/MIME, the mail header becomes corrupted. The php function openssl_pkcs7_sign adds a "\n" before the "Content-Type" entry, which is transformed to a white space.

The invalid mail header looks like:

MIME-Version: 1.0
 Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha-256"; boundary="----35E3912ECCCEC346C448DBC105A6ED51"

Notice the space before Content-Type-line!

Here is a fix for version 6.9.1 for the file PHPMailer.php:

3117c3117
<                     $this->MIMEHeader .= str_replace("\n", static::$LE, $parts[0]) . static::$LE . static::$LE;
---
>                     $this->MIMEHeader .= $parts[0] . static::$LE . static::$LE;