Make WordPress Core

Changeset 54529


Ignore:
Timestamp:
10/17/2022 11:40:36 AM (17 months ago)
Author:
audrasjb
Message:

Mail: Reset PHPMailer properties between use.

Props xknown, martinkrcho, tykoted.

Location:
trunk
Files:
2 edited

Legend:

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

    r54397 r54529  
    354354        $phpmailer->clearCustomHeaders();
    355355        $phpmailer->clearReplyTos();
     356        $phpmailer->Body    = '';
     357        $phpmailer->AltBody = '';
    356358
    357359        // Set "From" name and email.
  • trunk/tests/phpunit/tests/mail.php

    r53900 r54529  
    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( 'user1@example.localhost', 'Test 1', '<p>demo</p>', 'Content-Type: text/html' );
     490        remove_action( 'phpmailer_init', $wp_mail_set_text_message );
     491        wp_mail( 'user2@example.localhost', 'Test 2', 'test2' );
     492        $phpmailer = $GLOBALS['phpmailer'];
     493        $this->assertNotSame( 'user1', $phpmailer->AltBody );
     494    }
    478495}
Note: See TracChangeset for help on using the changeset viewer.