Specifying Sender Details

An email must include information about who sent it. Usually this is managed by the From: address, however there are other options.

The sender information is contained in three possible places:
  1. From: – the address(es) of who wrote the message (required)
  2. Sender: – the address of the single person who sent the message (optional)
  3. Return-Path: – the address where bounces should go to (optional)

You must always include a From: address by using setFrom() on the message. Swift Mailer will use this as the default Return-Path: unless otherwise specified.

The Sender: address exists because the person who actually sent the email may not be the person who wrote the email. It has a higher precedence than the From: address and will be used as the Return-Path: unless otherwise specified.

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.