32

How can reply-to be set when using Swiftmailer. The docs mentioned the function setReplyTo() but without specific instructions on how to use it.

Any help will be appreciated.

Dave
  • 3,328
  • 7
  • 26
  • 30
  • 1
    It needs an address as specified in the docs: http://swiftmailer.org/docs/messages.html#the-structure-of-a-message - should work like return-path: http://swiftmailer.org/docs/messages.html#setting-the-return-path-bounce-address – hakre Aug 03 '11 at 23:52

2 Answers2

52

I can confirm that the setReplyTo method works the same way as (for example) the setCC method.

$message->setReplyTo(array(
  'person1@example.org',
  'person2@otherdomain.org' => 'Person 2 Name',
  'person3@example.org',
  'person4@example.org',
  'person5@example.org' => 'Person 5 Name'
));
Lode
  • 2,160
  • 1
  • 20
  • 25
1

For those who experienced the same confusion as me, you are not able to run $recipients->setReplyTo() on a Swift_RecipientList but you are able to do so on the Swift_Message directly:

$recipients = new Swift_RecipientList;
// this is correct
$recipients->addTo('some@email.com');
// this method does not exist so this does not work
$recipients->addReplyTo('some.other@email.com');

$message = new Swift_Message($subject, $message, 'text/html');
// you can, however, add the reply-to here like this
$message->setReplyTo('some.other@email.com');
// and of course sending the e-mail like this with the reply to works
$swift->send($message, $recipients, 'some@email.com');
Ken
  • 2,859
  • 4
  • 24
  • 26