WordPress.org

Make WordPress Core

Ticket #47855: wp-email-validate-check.php

File wp-email-validate-check.php, 2.1 KB (added by yolabingo, 2 years ago)

simple script to test the

Line 
1<?php
2
3/*
4When using a current PHP version, class-phpmailer.php:validateAddress() uses a complex regex ("pcre8") for email address validation.
5
6PHP < 7.3 uses libpcre 8.x.
7PHP 7.3 uses libpcre2 10.x.
8Due to a bug in libpcre2 < 10.32-RC1 https://bugs.exim.org/show_bug.cgi?id=2300,
9this email regex validation fails in PHP 7.3 with PCRE_VERSION < 10.32.
10
11One consequence of this is being unable to send a password reset link from the login page.
12Submissions to /wp-login.php?action=lostpassword will show the error
13"The email could not be sent. Possible reason: your host may have disabled the mail() function."
14
15Sample outputs from this script:
16=-=-=-=-=-=-=-=-=-=-=-=
17PHP version: 7.2.18
18PCRE version: 8.41 2017-07-05
191
20Wordpress email validation preg_match succeeded
21=-=-=-=-=-=-=-=-=-=-=-=
22PHP version: 7.3.7
23PCRE version: 10.30 2017-08-14
24
25Wordpress email validation preg_match failed
26=-=-=-=-=-=-=-=-=-=-=-=
27PHP version: 7.3.7
28PCRE version: 10.32 2018-09-10
291
30Wordpress email validation preg_match succeeded
31=-=-=-=-=-=-=-=-=-=-=-=
32*/
33
34
35$email_regex = '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD';
36
37
38echo "PHP version: " . phpversion() . "\n";
39
40echo "PCRE version: " . PCRE_VERSION . "\n";
41echo preg_match($email_regex, "example@wordpress.com") . "\n";
42if (preg_match($email_regex, "example@wordpress.com")) {
43    echo "Wordpress email validation preg_match succeeded";
44} else {
45    echo "Wordpress email validation preg_match failed";
46}
47echo "\n";