使用Swiftmailer时如何设置回复地址

32

当使用Swiftmailer时,如何设置回复地址(reply-to)。文档中提到了函数setReplyTo(),但没有具体的使用说明。

欢迎任何帮助和支持。


1
它需要一个在文档中指定的地址:http://swiftmailer.org/docs/messages.html#the-structure-of-a-message - 应该像return-path一样工作:http://swiftmailer.org/docs/messages.html#setting-the-return-path-bounce-address - hakre
2个回答

52

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

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

1

如果你和我一样感到困惑,那么你无法在Swift_RecipientList上运行$recipients->setReplyTo(),但是你可以直接在Swift_Message上这样做:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接