Addresses in Swift Mailer

Addresses are specified with a basic array syntax that can include the name associated with the address.

Syntax for Addresses

If you only wish to refer to a single email address (for example your From: address) then you can just use a string.

$message->setFrom('some@address.tld');

If you want to include a name then you must use an associative array.

$message->setFrom(array('some@address.tld' => 'The Name'));

If you want to include multiple addresses then you must use an array.

$message->setTo(array('some@address.tld', 'other@address.tld'));

You can mix personalized (addresses with a name) and non-personalized addresses in the same list by mixing the use of associative and non-associative array syntax.

$message->setTo(array(
  'recipient-with-name@example.org' => 'Recipient Name One',
  'no-name@example.org', //Note that this is not a key-value pair
  'named-recipient@example.org' => 'Recipient Name Two'
));

NOTE: Documentation for version 3 is in the wiki.