0

我会用 SwiftMail 4.1.1 创建一个 php 时事通讯脚本,但我只在http://swiftmailer.org/wikidocs/v3/sending/batch为 Swift v.3 创建了 wiki 对于 Swift 4.1.1 没有 wiki http://swiftmailer.org/wikidocs/v4/start

我该如何处理 Swift v.4?v.3 的相同代码不起作用。

非常感谢。

4

2 回答 2

2

好的,根据您的要求-

如果您想批量发送电子邮件

根据 http://swiftmailer.org/docs/sending.html上的最新文档

批量发送邮件¶

如果您想向每个收件人发送单独的消息,以便在“收件人:”字段中仅显示他们自己的地址,请遵循以下方法:

require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('receiver@domain.org', 'other@domain.org' => 'A name');

foreach ($to as $address => $name)
{
  $message->setTo(array($address => $name));
  $numSent += $this->send($message, $failedRecipients);
}

printf("Sent %d messages\n", $numSent);

使用 batchSend() - 我不确定在您需要的版本中是否可用?

$mailer_instance = Swift_Mailer::newInstance($mail_transport_instance);
$message_instance = Swift_Message::newInstance()
      ->setSubject($subject)
      //Set the From address with an associative array
      ->setFrom($mail_from)
      //Set the To addresses with an associative array
      ->setTo($mail_to);
      //some other options as required

$num_sent = $mailer_instance->batchSend($message_instance);

我希望它有所帮助。

于 2011-08-08T11:25:33.170 回答
1

Swiftmailer 4 已被重写,该类Swift_RecipientList在 Swiftmailer 4 中不可用。

请参阅Swiftmailer 4 关于 Sending Messages的文档,其中有一个名为Sending Emails in Batch的部分,也许这就是您要查找的内容。

于 2011-08-08T10:51:23.420 回答