How could I parse email addresses which are in this format :
"Bob Smith" <bob@company.com>, joe@company.com, "John Doe"<john@company.com>
And get an array like this :
array(
'bob@company.com'=>'Bob Smith'
'joe@company.com'=>''
'john@company.com'=>'John Doe'
);
We have something similar to mailparse_rfc822_parse_addresses() with Laravel?
You can extract all emails from string with this function:
function extract_email_address_from_string ($string) {
foreach(preg_split('/\s/', $string) as $token) {
$email = filter_var(filter_var($token, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
if ($email !== false) {
$emails[] = $email;
}
}
return $emails;
}