使用 Swiftmailer 时如何设置回复

2022-08-30 14:16:46

如何使用 Swiftmailer 时设置 reply-to。文档提到了函数 setReplyTo(),但没有关于如何使用它的具体说明。

任何帮助将不胜感激。


答案 1

我可以确认该方法的工作方式与(例如)setCC方法相同。setReplyTo

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

答案 2

对于那些经历过与我相同的困惑的人来说,你不能在Swift_RecipientList上运行,但你可以在Swift_Message直接这样做:$recipients->setReplyTo()

$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');

推荐