Make WordPress Core


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

Mail: Reset PHPMailer properties between use.

Props xknown, martinkrcho, tykoted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.