I am using SwiftMailer to send bulk emails. At the moment, I do it with the code
$transport = Swift_SmtpTransport::newInstance('*****', 25);
$transport->setUsername('***');
$transport->setPassword('***');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject($derBetreff);
$bbc= array('1@web.de','2@web.de','3@web.de',...,'1000@web.de');
$message->setFrom(array('my@email.de' => 'My Name'));
$message->setTo('my@email.de');
$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;
where I only send a single email to myself and add ~1000 people in the BCC.
It takes about 9 minutes to execute the code and send one single email and it returns a 'success' message. However, my max_execution_time in my php.ini file is only set to 30 seconds.
My first question is: Why does the max_execution_time not stop my SwiftMailer script?
Secondy, I found the AntiFlood Plugin for Swiftmailer which helps to send bulk emails. The script below sends each member a single email by sending 100 emails first and then pause for 30 seconds and continuing sending the next 100 emails and so on. I have read that this is good practice to circumvent being marked as spam.
My second question is: Does the AntiFlood Plugin need an extraordinary long execution time in order to work? For example, if I send 1000 emails with the script given below and only take the pausing into consideration, then the script runs already at least 4.5 minutes, right?
// 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( ... );
}