#59670 closed defect (bug) (duplicate)
"Content-Transfer-Encoding" might break when sending multiple mails
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 6.3.2 |
| Component: | Keywords: | ||
| Focuses: | Cc: |
Description
When sending multiple non-multipart mails via wp_mail the internal encoding used by PhpMailer doesn't get resetted which may result in mails getting the wrong Content-Transfer-Encoding.
wp_mail('someone@somehost.tld', '8bit', '8büt'); // correctly delivered as 8bit
wp_mail('someone@somehost.tld', '7bit', '7bit'); // correctly delivered as 7bit but breaks the following mails
wp_mail('someone@somehost.tld', '8bit', '8büt'); // incorrectly delivered as 7bit
Internally PhpMailer starts with 8bit encoding in $phpMailer->Encoding. When sending a mail it might get downgraded/changed to 7bit in case the message doesn't contain any 8bit chars (which is the case in the first mail).
However because of WP reusing the same PhpMailer instance the encoding doesn't get resetted to 8bit back again and therefore stays at 7bit.
The easiest solution would be resetting the encoding manually or using an appropriate PhpMailer method if existing.
Another solution would be for PhpMailer to be able to upgrade the encoding back to 8bit again when detecting 8bit chars.
IMHO this depends on whether one PhpMailer instance is intended to be used for multiple mails or not.
See:
- Default encoding of PhpMailer: https://build.trac.wordpress.org/browser/tags/6.3.2/wp-includes/PHPMailer/PHPMailer.php#L92
- Setting
Content-Transfer-Encodingin case its not 7bit: https://build.trac.wordpress.org/browser/tags/6.3.2/wp-includes/PHPMailer/PHPMailer.php#L2744 - Downgrading of Encoding to 7bit: https://build.trac.wordpress.org/browser/tags/6.3.2/wp-includes/PHPMailer/PHPMailer.php#L2840
This issue triggers the SpamAssassin rule
CTE_8BIT_MISMATCH"Header says 7bits but body disagrees".See: https://svn.apache.org/repos/asf/spamassassin/tags/sa-update_3.4.4_20200729083044/rulesrc/sandbox/davej/20_non_ascii.cf