#17305 closed defect (bug) (fixed)
wp_mail() does not accommodate address format "Name <address@tld.com>"
Reported by: | dllh | Owned by: | westi |
---|---|---|---|
Milestone: | 3.2 | Priority: | normal |
Severity: | normal | Version: | 3.2 |
Component: | Keywords: | has-patch | |
Focuses: | Cc: |
Description
The wp_mail() function does not accommodate addresses in the form "Name <address@…>". The phpmailer class chokes on this format, as the whole string is passed to its $address parameter rather than the constituent parts being passed as $address and $name. This does not likely affect a great many mailer functions in core, but it does stand to affect plugins (and does affect some wpcom plugins). The attached patch resolves the issue.
If I can provide any further information to increase the likelihood of landing this pretty quickly so that it can land on wpcom, please speak up.
Attachments (1)
Change History (15)
#6
@
13 years ago
- Owner set to westi
- Status changed from new to assigned
Seeing as mail()
supports RFC2822 addressing there should be no reason why we don't
Looking into this to see if it is a regression from the new PHPMailer.
#8
@
13 years ago
While writing the above test cases I discovered that we also need to apply this same logic to bcc and cc addresses :)
#11
@
13 years ago
- Cc kitchin added
- Keywords needs-codex added
I am adding "needs-codex" so users can see the new feature.
This landed patch works, but could have been better. The regex has a part which does not work. The problem is fixed later in AddAnAddress(), so there is no real bug.
Details: The "\s?" in the regex does nothing, due to the greedy "+" beforehand (minor exception below). In the typical case, "Foo <bar@…>", the $recipient_name is right-padded: 'Foo ' instead of 'Foo'.
The string is trimmed later, after $phpmailer->AddAddress(), or AddCc(), or AddBcc(), call AddAnAddress(), which trims both the address and the name.
Several fixes are possible for this bad looking code, with no change in behavior. The best is to simplify the regexes to '/(.+)<(.+)>/' and call trim() in both arguments (or neither):
$phpmailer->AddAddress( trim($recipient), $recipient_name );
...AddCc...
...AddBcc...
That has no change in behavior.
An ENHANCEMENT would be to allow "<bar@…>" by making the regexes: '/(.*)<(.+)>/'.
Minor exception above: the "\s?" in the regex will catch a single "\n". But that is not a documented feature of wp_mail().
#12
follow-up:
↓ 13
@
13 years ago
- Cc pavelevap@… added
I am not sure if I understand it well, but in WP 3.2 my headers with Bcc adresses with format "<address@...>" stopped working. I had to remove brackets and new format "address@..." works well now...
#13
in reply to:
↑ 12
@
13 years ago
OK, filed Ticket #18463 wp_mail() does not allow"<address@…>", regression, since it appears the format "<address@…>" worked before this bug, and my regex would restore that feature.
Replying to pavelevap:
I am not sure if I understand it well, but in WP 3.2 my headers with Bcc adresses with format "<address@...>" stopped working. I had to remove brackets and new format "address@..." works well now...
Adds check for "Foo <a@…>" format.