Wednesday, 28 August 2019

Can I use a traditional Email "To" line in SwiftMailer?

SwiftMailer expects an array of e-mail addresses, possibly including names as values of the array:

$message->setTo([
  'person1@example.org',
  'person2@example.net' => 'Person 2 Name',
  'person3@example.org',
  'person4@example.org',
  'person5@example.org' => 'Person 5 Name'
]);

But what I have is a single line of text, forming a standard To header:

person1@example.org, 'Person 2 Name' <person2@example.net>, person3@example.org, person4@example.org, 'Person 5 Name' <person5@example.org>

I can probably hack something together to convert the To header to an array, but this feels like a problem with a standard solution, ideally from someone who has absorbed the RFCs and will accept weird but valid e-mail addresses, including ones that contain commas and semi-colons. Does SwiftMailer itself have a function for this? If so, I can’t find it.



from Can I use a traditional Email "To" line in SwiftMailer?

No comments:

Post a Comment