Index: src/wp-includes/pluggable.php =================================================================== --- src/wp-includes/pluggable.php (revision 48525) +++ src/wp-includes/pluggable.php (working copy) @@ -2832,3 +2832,35 @@ } endif; +if ( ! function_exists( 'wp_set_phpmailer_validator' ) ) : + /** + * Sets the PHPMailer's validator to a value determined by the environment. + * + * The logic is the same as in the auto mode of PHPMailer 5.2.27 version. + * + * @param PHPMailer $phpmailer The PHPMailer object. + */ + function wp_set_phpmailer_validator( $phpmailer ) { + // Check this constant first so it works when extension_loaded() is disabled by safe mode. + // Constant was added in PHP 5.2.4. + if ( defined( 'PCRE_VERSION' ) ) { + // This pattern can get stuck in a recursive loop in PCRE <= 8.0.2. + if ( version_compare( PCRE_VERSION, '8.0.3' ) >= 0 ) { + $patternselect = 'pcre8'; + } else { + $patternselect = 'pcre'; + } + } elseif ( function_exists( 'extension_loaded' ) && extension_loaded( 'pcre' ) ) { + // Fall back to older PCRE. + $patternselect = 'pcre'; + } else { + // Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension. + if ( version_compare( PHP_VERSION, '5.2.0' ) >= 0 ) { + $patternselect = 'php'; + } else { + $patternselect = 'noregex'; + } + } + $phpmailer::$validator = $patternselect; + } +endif; Index: src/wp-includes/class-phpmailer.php =================================================================== --- src/wp-includes/class-phpmailer.php (revision 48525) +++ src/wp-includes/class-phpmailer.php (working copy) @@ -17,3 +17,6 @@ class_alias( PHPMailer\PHPMailer\PHPMailer::class, 'PHPMailer' ); class_alias( PHPMailer\PHPMailer\Exception::class, 'phpmailerException' ); + +wp_set_phpmailer_validator( new PHPMailer\PHPMailer\PHPMailer ); +