我使用SwiftMailer發送大量電子郵件。目前,我使用代碼使用Swiftmailer發送大量電子郵件
$transport = Swift_SmtpTransport::newInstance('*****', 25);
$transport->setUsername('***');
$transport->setPassword('***');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject($derBetreff);
$bbc= array('[email protected]','[email protected]','[email protected]',...,'[email protected]');
$message->setFrom(array('[email protected]' => 'My Name'));
$message->setTo('[email protected]');
$message->setBcc($bcc);
$message->setBody('Hi this is my email');
$message->attach(Swift_Attachment::fromPath('myFile.pdf'));
// Send the message
$result = $mailer->send($message);
echo $result;
在那裏我只發送一封郵件給自己並在BCC中添加約1000人。
大約需要9分鐘執行代碼,併發送一個電子郵件地址和它返回一個「成功」的消息。但是,我的php.ini文件中的max_execution_time的僅設置爲30秒。
我的第一個問題是:爲什麼的max_execution_time無法阻擋我SwiftMailer腳本?
Secondy,我發現AntiFlood Plugin for Swiftmailer這有助於發送大量電子郵件。下面的腳本通過先發送100封電子郵件然後暫停30秒並繼續發送接下來的100封電子郵件等等,向每個成員發送一封電子郵件。我已經讀過,這是避免被標記爲垃圾郵件的好習慣。
我的第二個問題是:是否抗洪插件需要一個非常長的執行時間,以工作?例如,如果我發送1000封帶有下面腳本的電子郵件,並且只考慮暫停,那麼腳本已經運行了至少4.5分鐘,對吧?
// Create the Mailer using any Transport
$mailer = Swift_Mailer::newInstance(
Swift_SmtpTransport::newInstance('smtp.example.org', 25)
);
// Use AntiFlood to re-connect after 100 emails
$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100));
// And specify a time in seconds to pause for (30 secs)
$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100, 30));
// Continue sending as normal
for ($lotsOfRecipients as $recipient) {
...
$mailer->send(...);
}
嗨,我需要完成這個確切的事情,你怎麼最終這樣做? –
@LeeWiggins你可以安全地使用防洪插件,甚至更好的郵件查詢。我在這裏添加了一個答案:https://stackoverflow.com/a/47922195/2311074 – Adam