diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 5d65e53f8b..c2a975d896 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -353,6 +353,8 @@ if ( ! function_exists( 'wp_mail' ) ) : $phpmailer->clearAttachments(); $phpmailer->clearCustomHeaders(); $phpmailer->clearReplyTos(); + $phpmailer->Body = ''; + $phpmailer->AltBody = ''; // Set "From" name and email. diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index c130658e3f..53eacbd7f5 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -475,4 +475,21 @@ class Tests_Mail extends WP_UnitTestCase { $this->assertTrue( $result1 ); $this->assertFalse( $result2 ); } + + /** + * Tests that AltBody is reset between each wp_mail call. + * + * @covers :wp_mail + */ + public function test_wp_mail_resets_properties() { + $wp_mail_set_text_message = function ( $phpmailer ) { + $phpmailer->AltBody = 'user1'; + }; + add_action( 'phpmailer_init', $wp_mail_set_text_message ); + wp_mail( 'user1@example.localhost', 'Test 1', '

demo

', 'Content-Type: text/html' ); + remove_action( 'phpmailer_init', $wp_mail_set_text_message ); + wp_mail( 'user2@example.localhost', 'Test 2', 'test2' ); + $phpmailer = $GLOBALS['phpmailer']; + $this->assertNotSame( 'user1', $phpmailer->AltBody ); + } }