[wp-trac] [WordPress Trac] #51030: Error in wp_mail function

WordPress Trac noreply at wordpress.org
Wed Aug 19 02:21:39 UTC 2020


#51030: Error in wp_mail function
-------------------------------+---------------------
 Reporter:  hichembelhadj      |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  5.5.1
Component:  Mail               |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+---------------------

Comment (by khag7):

 Prior to 5.5 the `wp_mail` function used PHPMailer's validator function to
 validate emails. By default, `PHPMailer::$validator` variable was set to
 `auto`, and PHPMailer would then attempt to use a somewhat complex regex
 to validate emails.

 The PHPMailer `auto` option was using pcre8 (if avaliable) and
 `wordpress at localhost` would be valid in that case.

 With the update to the newest version of PHPMailer (#41750) the `auto`
 option is no longer available, and instead uses the `php` validation
 option. Shortly after #41750 was closed, this proved to be an issue
 (#50720) so WP core moved to using our own `is_email` function for
 validation.

 Unfortunately, WordPress's `is_email` function does not consider
 `wordpress at localhost` to be a valid email, thus this ticket exists.

 I think we may have been quick to jump to using our own `is_email`
 function when another better option exists. The PHPMailer class includes a
 validation option called `html5` which I think would work.

 Some quick tests show the following statements to be true:
 `false=== is_email( 'wordpress at localhost' )`
 `true ===
 PHPMailer\PHPMailer\PHPMailer::validateAddress('wordpress at localhost','html5')`
 `false===
 PHPMailer\PHPMailer\PHPMailer::validateAddress('wordpress at localhost','php')`
 `true ===
 PHPMailer\PHPMailer\PHPMailer::validateAddress('wordpress at localhost','pcre8')`

 As of 5.5, in `wp_mail` we assign `$phpmailer::$validator` to a function
 which wraps `is_email`.
 **Perhaps instead we should just do `$phpmailer::$validator = 'html5'`?**

 Alternatively we improve `is_email` to support emails with a domain that
 does not include a period.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51030#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list