diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index c614ac0ed6..b2ed4642c5 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -216,6 +216,10 @@ if ( ! function_exists( 'wp_mail' ) ) : require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true ); + + $phpmailer::$validator = static function ( $email ) { + return (bool) is_email( $email ); + }; } // Headers. diff --git a/tests/phpunit/includes/mock-mailer.php b/tests/phpunit/includes/mock-mailer.php index edc36b9ec6..e5e3d98fa2 100644 --- a/tests/phpunit/includes/mock-mailer.php +++ b/tests/phpunit/includes/mock-mailer.php @@ -96,7 +96,12 @@ function tests_retrieve_phpmailer_instance() { function reset_phpmailer_instance() { $mailer = tests_retrieve_phpmailer_instance(); if ( $mailer ) { - $GLOBALS['phpmailer'] = new MockPHPMailer( true ); + $mailer = new MockPHPMailer( true ); + $mailer::$validator = static function ( $email ) { + return (bool) is_email( $email ); + }; + + $GLOBALS['phpmailer'] = $mailer; return true; } diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index d24d5e831a..f520e1e5a0 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -407,4 +407,12 @@ class Tests_Mail extends WP_UnitTestCase { $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() ); $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() ); } + + /** + * @ticket 50720 + */ + function test_phpmailer_validator() { + $phpmailer = $GLOBALS['phpmailer']; + $this->assertTrue( $phpmailer->validateAddress( 'foo@192.168.1.1' ), 'Assert PHPMailer accepts IP address email addresses' ); + } }