Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#17305 closed defect (bug) (fixed)

wp_mail() does not accommodate address format "Name <address@tld.com>"

Reported by: dllh's profile dllh Owned by: westi's profile westi
Milestone: 3.2 Priority: normal
Severity: normal Version: 3.2
Component: Mail 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)

17305.patch (670 bytes) - added by dllh 13 years ago.
Adds check for "Foo <a@…>" format.

Download all attachments as: .zip

Change History (15)

@dllh
13 years ago

Adds check for "Foo <a@…>" format.

#1 @kawauso
13 years ago

  • Keywords has-patch added

#2 @dllh
13 years ago

  • Cc daryl@… removed

#3 @dllh
13 years ago

  • Cc daryl@… added

#4 @kardotim
13 years ago

  • Cc kardotim added

#5 @knutsp
13 years ago

  • Cc knut@… added

#6 @westi
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.

#7 @westi
13 years ago

Test cases: [UT359]

#8 @westi
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 :)

#9 @westi
13 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In [18006]:

Update wp_mail to correctly call the Address adding functions on PHPMailer for To, CC, BCC in a way which preserves our support for full RFC2822 address specifications.
Older versions of PHPMailer were not too careful about validating what we passed in to them as a plain email address - the new version expects we pass in the Name and Email address seperately.
Fixes #17305 based on a patch from dllh.

#10 @westi
13 years ago

  • Milestone changed from Awaiting Review to 3.2
  • Version changed from 3.1 to 3.2

#11 @kitchin
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: @pavelevap
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 @kitchin
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...

Last edited 13 years ago by kitchin (previous) (diff)

#14 @bcworkz
11 years ago

  • Keywords needs-codex removed

Added section to Codex with addressing examples

Note: See TracTickets for help on using tickets.