Make WordPress Core


Ignore:
Timestamp:
11/04/2025 05:18:55 PM (5 months ago)
Author:
johnjamesjacoby
Message:

Mail: reset Encoding to 8-bit in wp_mail().

The PHPMailer library may automatically switch its encoding based on various internal factors.

This commit fixes a bug where the $phpmailer global was unintentionally persisting its Encoding property from the first wp_mail() call to all subsequent calls.

This includes unit tests to verify the fix is accurate, and a change to the mock-mailer helper that worked around this bug just-in-time when running the test suite.

Props codebuddy, dilip2615, rishabhwp, sajjad67, sirlouen, stephenharris.

Fixes #33972.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r61038 r61131  
    384384        $phpmailer->Body    = '';
    385385        $phpmailer->AltBody = '';
     386
     387        /*
     388         * Reset encoding to 8-bit, as it may have been automatically downgraded
     389         * to 7-bit by PHPMailer (based on the body contents) in a previous call
     390         * to wp_mail().
     391         *
     392         * See https://core.trac.wordpress.org/ticket/33972
     393         */
     394        $phpmailer->Encoding = PHPMailer\PHPMailer\PHPMailer::ENCODING_8BIT;
    386395
    387396        // Set "From" name and email.
Note: See TracChangeset for help on using the changeset viewer.