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.
- To: recipients – the primary recipients (required)
- Cc: recipients – receive a copy of the message (optional)
- 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' ));
-
Setting To: Recipients
To: recipients are required in a message and are set with the setTo() or addTo() methods of the message. -
Setting Cc: Recipients
Cc: recipients are set with the setCc() or addCc() methods of the message. -
Setting Bcc: Recipients
Bcc: recipients receive a copy of the message without anybody else knowing it, and are set with the setBcc() or addBcc methods of the message.