Mail: PHPMailer swap to use is_email for the default validator.

Prior to the PHPMailer update in 5.5, old version of the PHPMailer was setting the validator to 'auto' resulting in a sophisticated logic for determining what email address validation should be used. But the new version defaults to 'php', possibly leading to rejection of email addresses which were fine prior to the upgrade. Let's use the WordPress core function `is_email()` so that it can be fully pluggable.

Fixes #50720.
Props david.binda, ayeshrajans, Synchro, SergeyBiryukov, whyisjake.


git-svn-id: https://develop.svn.wordpress.org/trunk@48645 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2020-07-27 20:17:36 +00:00
parent e03be98644
commit 8c9b33c3b6
3 changed files with 18 additions and 1 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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' );
}
}