diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index c614ac0ed6..caad610b79 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -216,6 +216,14 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true ); + + /** + * Set email validation to use WordPress's built-in is_email(). + * @ticket 50720 + */ + $phpmailer::$validator = static function ( $email ) { + return is_email( $email ) !== false; + }; } // Headers. diff --git a/tests/phpunit/includes/mock-mailer.php b/tests/phpunit/includes/mock-mailer.php index edc36b9ec6..04a76601d6 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 is_email( $email ) !== false; + }; + + $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 @@ public function test_phpmailer_exception_thrown() { $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' ); + } }