diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 1dbac5e1d707c..fcbdb3424b742 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -356,8 +356,9 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() $phpmailer->clearAttachments(); $phpmailer->clearCustomHeaders(); $phpmailer->clearReplyTos(); - $phpmailer->Body = ''; - $phpmailer->AltBody = ''; + $phpmailer->Body = ''; + $phpmailer->AltBody = ''; + $phpmailer->Encoding = PHPMailer\PHPMailer\PHPMailer::ENCODING_8BIT; // Set "From" name and email. diff --git a/tests/phpunit/tests/pluggable/wpMail.php b/tests/phpunit/tests/pluggable/wpMail.php index 7b88d739add22..4884837b189fd 100644 --- a/tests/phpunit/tests/pluggable/wpMail.php +++ b/tests/phpunit/tests/pluggable/wpMail.php @@ -554,4 +554,22 @@ public function test_wp_mail_resets_properties() { $phpmailer = $GLOBALS['phpmailer']; $this->assertNotSame( 'user1', $phpmailer->AltBody ); } + + /** + * Test that the encoding of the email does not bleed between long and short emails. + * + * @ticket 33972 + */ + public function test_wp_mail_encoding_does_not_bleed() { + $content = str_repeat( 'A', 1000 ); + wp_mail( WP_TESTS_EMAIL, 'Looong line testing', $content ); + + $mailer = tests_retrieve_phpmailer_instance(); + $this->assertEquals( 'quoted-printable', $mailer->Encoding ); + + wp_mail( WP_TESTS_EMAIL, 'A follow up short email', 'Short email –' ); + + $mailer = tests_retrieve_phpmailer_instance(); + $this->assertEquals( '8bit', $mailer->Encoding ); + } }