[wp-trac] [WordPress Trac] #62940: wp_mail(): Address header parsing is not RFC-5322 complient and fails on quoted-string when including a "<", ">" or ", "

WordPress Trac noreply at wordpress.org
Sat Aug 23 00:02:40 UTC 2025


#62940: wp_mail(): Address header parsing is not RFC-5322 complient and fails on
quoted-string when including a "<", ">" or ","
-------------------------------------------------+-------------------------
 Reporter:  bhujagendra                          |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Mail                                 |     Version:  2.1.1
 Severity:  normal                               |  Resolution:
 Keywords:  needs-patch needs-unit-tests has-    |     Focuses:
  test-info                                      |
-------------------------------------------------+-------------------------
Changes (by SirLouen):

 * milestone:  Awaiting Review => Future Release


Comment:

 @jdeep

 After thinking about this problem I don't really see any point on going
 beyond imap support. Its like: you want advanced features? Install `imap`
 extension, don't ask me to upgrade to a fully featured RFC822 parser for
 something that is going to be used by maybe 0.01% of the WP population.

 Currently `parseAddresses` support full rfc822 address splitting in all
 the variants. In fact I'm proposing to `PHPMailer` to water down the
 non-`imap`-ext version as much as possible. We cannot reinvent the wheel.
 So, since we have access to the latest version of `PHPMailer` which
 happens to be integrated as an External Library, and it has
 `parseAddresses`, lets use it.

 Now I'm thinking if we could take a check based on the code, to create a
 Site Health check to recommend `php-imap` extension installed based on
 something we pick from code because the sole use of this is through custom
 mail headers, its so niche that its undetectable.

 But definitely the addresses parsing in the headers part should leave.
 It's excessively simple and for pretty much all simple use-cases,
 `parseAddresses` does the trick (even without the `imap` version)

 For the other part of the ticket, the multiple `From` addresses, I'm doing
 a bit more research. For now, from the native support perspective this
 would not be feasible as `setFrom` doesnt support multiple Froms. And from
 the Headers perspective, we are having a massive trouble with the former,
 as our Header parsing options are disastrous.

 So lets take one thing at a time. Maybe we can open a second ticket in the
 future to handle the multiple From part. For now lets try to fix the first
 as I commented in the beginning (with the `parseAddresses` support in
 exchange on the weak logic for parsing headers in the current code)

 We also need unit tests for this.

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


More information about the wp-trac mailing list