[英]sending newsletter with swift 4.1.1
我會使用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的相同代碼無法正常工作。
非常感謝。
確定,根據您的要求-
如果要批量發送電子郵件
根據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);
希望對您有所幫助。
Swiftmailer 4已經被改寫,類Swift_RecipientList
不可用Swiftmailer 4。
請參閱Swiftmailer 4的有關發送消息的文檔,其中有一個名為批量發送電子郵件的部分,也許正是您所需要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.