Opened 13 years ago
Closed 6 months ago
#23243 closed defect (bug) (worksforme)
wp_mail() not working with "Name <email>" format in buggy PHP versions on Windows
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | minor | Version: | 3.5 |
| Component: | Keywords: | ||
| Focuses: | Cc: |
Description
As a result of ticket #17305, wp_mail() accepts the $to parameter in the format "Name <email@…>".
There exists a PHP bug in versions below 5.2.11 and in 5.3, on Windows. This bug occurs when addresses are passed to the PHP mail() function in the "Name <email>" format and prevents e-mails from being sent. I believe this bug in fixed in 5.3.1 and above. (see https://bugs.php.net/bug.php?id=28038)
I don't believe this affects any core functionality, but may affect some plugins which pass $to in the above format.
I tested in PHP 5.2.4 on Windows with the following code:
wp_mail("email@ext.com", "Test", "Test");
wp_mail("Name <email@ext.com>", "Test 2", "Test 2");
The first email is received; the second isn't. When removing error suppression from the mail() calls in class-phpmailer.php, the following warning is outputted:
Warning: mail() [function.mail]: SMTP server response: 501 <Name <email@…>>: "@" or "." expected after "Name" in C:\xampplite\htdocs\wp-includes\class-phpmailer.php on line 771
Change History (6)
#3
@
13 years ago
#23291 no longer triggers an entry in the PHP error log; instead it returns a WP_Error.
#5
@
10 years ago
Not to suggest that things shouldn't be resolved to handle things correctly, but if this is a bug in PHP below 5.2.11 and in 5.3 on Windows, how necessary is a patch/fix?
WP is now recommended to use PHP 5.6, and even though WP can run on these lower versions, they are technically beyond EOL (I realize that was not the case when this ticket was opened, but it is now).
#6
@
6 months ago
- Keywords needs-patch removed
- Resolution set to worksforme
- Status changed from new to closed
Reproduction Report
Description
❌ This report can't validate that the issue can be reproduced.
Environment
- WordPress: 6.8.2
- PHP: 8.2.18
- Server: Apache/2.4.59 (Win64) OpenSSL/3.1.5
- Database: mysqli (Server: 11.8.1-MariaDB-log / Client: mysqlnd 8.2.18)
- Browser: Chrome 138.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Testing Dolly 1.0.0
- Test Reports 1.2.0
Testing Instructions
- Enable a Windows web server with mail service
- Add
wp_mail("Name <email@ext.com>", "Test 2", "Test 2");where this could be executed - 👌Email is received as expected (check supplemental artifacts)
Actual Results
- ❌ Error condition is not occurring
Additional Notes
- As @cbutlerjr has suggested, given that 5.2 is no longer supported, I'm testing with a supported version just to confirm if this is currently working under a Windows PHP-based system.
- For this reason, it is time to close this ticket as
worksforme
Supplemental Artifacts
Return-Path: <test@example.com>
Received: from testwordpress.test (unknown [172.20.0.1])
by 144d19eeeff3 (Mailpit) with SMTP
for <email@ext.com>; Thu, 7 Aug 2025 10:59:20 +0000 (UTC)
Date: Thu, 7 Aug 2025 10:59:20 +0000
To: Name <email@ext.com>
From: test <test@example.com>
Subject: Test 2
Message-ID: <i1cFGSEO5Ruo7DjhxX93tIVBBa7D5SYsGbIbOu2ULA@testwordpress.test>
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Test 2
#23291 pushes any exceptions that PHPMailer throws to PHP's error_log. Since the bug was fixed in PHP two years ago, isn't triggered by core and only happens on Windows servers, then maybe the extra logging is enough?
If an actual workaround is desired, I would think it'd be more appropriate to do that upstream, rather than in WP.