How to set reply-to when using Swiftmailer
Asked Answered
V

2

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.

Volvulus answered 3/8, 2011 at 23:48 Comment(1)
It needs an address as specified in the docs: swiftmailer.org/docs/messages.html#the-structure-of-a-message - should work like return-path: swiftmailer.org/docs/…Sovran
H
52

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

$message->setReplyTo(array(
  '[email protected]',
  '[email protected]' => 'Person 2 Name',
  '[email protected]',
  '[email protected]',
  '[email protected]' => 'Person 5 Name'
));
Hautesavoie answered 6/10, 2011 at 15:26 Comment(0)
T
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('[email protected]');
// this method does not exist so this does not work
$recipients->addReplyTo('[email protected]');

$message = new Swift_Message($subject, $message, 'text/html');
// you can, however, add the reply-to here like this
$message->setReplyTo('[email protected]');
// and of course sending the e-mail like this with the reply to works
$swift->send($message, $recipients, '[email protected]');
Talky answered 22/8, 2019 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.