Make WordPress Core

Changeset 54539


Ignore:
Timestamp:
10/17/2022 12:34:37 PM (2 years ago)
Author:
audrasjb
Message:

Mail: Reset PHPMailer properties between use.

Props xknown, martinkrcho, tykoted.
Merges [54529] to the 6.0 branch.

Location:
branches/6.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.0

  • branches/6.0/src/wp-includes/pluggable.php

    r53301 r54539  
    362362        $phpmailer->clearCustomHeaders();
    363363        $phpmailer->clearReplyTos();
     364        $phpmailer->Body    = '';
     365        $phpmailer->AltBody = '';
    364366
    365367        // Set "From" name and email.
  • branches/6.0/tests/phpunit/tests/mail.php

    r52800 r54539  
    454454        $this->assertFalse( $result2 );
    455455    }
     456
     457    /**
     458     * Tests that AltBody is reset between each wp_mail call.
     459     *
     460     * @covers :wp_mail
     461     */
     462    public function test_wp_mail_resets_properties() {
     463        $wp_mail_set_text_message = function ( $phpmailer ) {
     464            $phpmailer->AltBody = 'user1';
     465        };
     466        add_action( 'phpmailer_init', $wp_mail_set_text_message );
     467        wp_mail( 'user1@example.localhost', 'Test 1', '<p>demo</p>', 'Content-Type: text/html' );
     468        remove_action( 'phpmailer_init', $wp_mail_set_text_message );
     469        wp_mail( 'user2@example.localhost', 'Test 2', 'test2' );
     470        $phpmailer = $GLOBALS['phpmailer'];
     471        $this->assertNotSame( 'user1', $phpmailer->AltBody );
     472    }
    456473}
Note: See TracChangeset for help on using the changeset viewer.