Similar to this question, how could I parse e-mail addresses which are in this format,
"Bob Smith" <bob@company.com>, joe@company.com, "John Doe"<john@company.com>
And get the a result like this:
array(
'bob@company.com'=>'Bob Smith'
'joe@company.com'=>''
'john@company.com'=>'John Doe'
);
For a similar task I've used the following regex:
https://regex101.com/r/Lpsjmr/1
PHP code:
Well, you could use
mailparse_rfc822_parse_addresses()
, which does exactly that. It's a PECL extension, so it might be easier to useMail_RFC822::parseAddressList()
as mentioned in the comments.This is a fully working piece of code below that even validates whether the email is correct or not ;)
This should work with just about anything:
Result: