开发者

sending newsletter with swift 4.1.1

I would create a php newsletter script with SwiftMail 4.1.1 but I have only founded the wiki for Swif开发者_StackOverflowt 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.


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

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜