使用 swift 4.1.1 发送新闻通讯

发布于 2024-11-28 16:51:48 字数 395 浏览 7 评论 0原文

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

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

多谢。

I would create a php newsletter script with SwiftMail 4.1.1 but I have only founded the wiki for Swift v.3 at http://swiftmailer.org/wikidocs/v3/sending/batch
For Swift 4.1.1 there isn't wiki http://swiftmailer.org/wikidocs/v4/start

How can I do with for Swift v.4? The same code for v.3 is not working.

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的往事 2024-12-05 16:51:49

好的,按照您的要求 -

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

请按照最新文档:
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('[email protected]' => 'John Doe'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('[email protected]', '[email protected]' => '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);

我希望它有帮助。

Ok as per your request -

If you want to send emails in a batch

As per latest documentation at
http://swiftmailer.org/docs/sending.html

Sending Emails in Batch¶

If you want to send a separate message to each recipient so that only their own address shows up in the To: field, follow the following recipe:

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('[email protected]' => 'John Doe'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('[email protected]', '[email protected]' => 'A name');

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

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

Using batchSend() - which I am not sure if is available in in your required version or not?

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

I hope it helps.

浮云落日 2024-12-05 16:51:49

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

请参阅文档 Swiftmailer 4 关于发送消息,有一个名为批量发送电子邮件的部分,也许就是这个你正在寻找。

Swiftmailer 4 has been rewritten, the class Swift_RecipientList is not available in Swiftmailer 4.

See the documentation for Swiftmailer 4 about Sending Messages, there is a section named Sending Emails in Batch, maybe that's what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文