Skip to content

Commit 3765886

Browse files
committed
Mail: Reset PHPMailer properties between use.
Props xknown, martinkrcho, tykoted. git-svn-id: https://develop.svn.wordpress.org/trunk@54529 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ebaac57 commit 3765886

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/wp-includes/pluggable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
353353
$phpmailer->clearAttachments();
354354
$phpmailer->clearCustomHeaders();
355355
$phpmailer->clearReplyTos();
356+
$phpmailer->Body = '';
357+
$phpmailer->AltBody = '';
356358

357359
// Set "From" name and email.
358360

tests/phpunit/tests/mail.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,21 @@ public function test_wp_mail_can_be_shortcircuited() {
475475
$this->assertTrue( $result1 );
476476
$this->assertFalse( $result2 );
477477
}
478+
479+
/**
480+
* Tests that AltBody is reset between each wp_mail call.
481+
*
482+
* @covers :wp_mail
483+
*/
484+
public function test_wp_mail_resets_properties() {
485+
$wp_mail_set_text_message = function ( $phpmailer ) {
486+
$phpmailer->AltBody = 'user1';
487+
};
488+
add_action( 'phpmailer_init', $wp_mail_set_text_message );
489+
wp_mail( '[email protected]', 'Test 1', '<p>demo</p>', 'Content-Type: text/html' );
490+
remove_action( 'phpmailer_init', $wp_mail_set_text_message );
491+
wp_mail( '[email protected]', 'Test 2', 'test2' );
492+
$phpmailer = $GLOBALS['phpmailer'];
493+
$this->assertNotSame( 'user1', $phpmailer->AltBody );
494+
}
478495
}

0 commit comments

Comments
 (0)