Adding Recipients to Your Message

Recipients are specified within the message itself via setTo(), setCc() and setBcc(). Swift Mailer reads these recipients from the message when it gets sent so that it knows where to send the message to.

Message recipients are one of three types:
  1. To: recipients – the primary recipients (required)
  2. Cc: recipients – receive a copy of the message (optional)
  3. Bcc: recipients – hidden from other recipients (optional)

Each type can contain one, or several addresses. It's possible to list only the addresses of the recipients, or you can personalize the address by providing the real name of the recipient.

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.