title: Bulk Email with Swiftmailer
body: <p>I am using <a href="http://swiftmailer.org/" rel="nofollow">SwiftMailer</a> to send bulk emails. At the moment, I do it with the code</p>
  
  <pre><code>$transport = Swift_SmtpTransport::newInstance('*****', 25);
  $transport-&gt;setUsername('***');
  $transport-&gt;setPassword('***');
  
  $mailer = Swift_Mailer::newInstance($transport);
  $message = Swift_Message::newInstance();
  $message-&gt;setSubject($derBetreff);
  
  $bbc= array('1@web.de','2@web.de','3@web.de',...,'1000@web.de');
  
  $message-&gt;setFrom(array('my@email.de' =&gt; 'My Name'));           
  $message-&gt;setTo('my@email.de');
  $message-&gt;setBcc($bcc);
  $message-&gt;setBody('Hi this is my email');           
  $message-&gt;attach(Swift_Attachment::fromPath('myFile.pdf'));     
  
  // Send the message
  $result = $mailer-&gt;send($message);
  echo $result;
  </code></pre>
  
  <p>where I only send a single email to myself and add ~1000 people in the BCC.</p>
  
  <p>It takes about 9 minutes to execute the code and send one single email and it returns a 'success' message. However, my <em>max_execution_time</em> in my php.ini file is only set to 30 seconds.</p>
  
  <p><strong>My first question is: Why does the max_execution_time not stop my SwiftMailer script?</strong></p>
  
  <p>Secondy, I found the <a href="http://swiftmailer.org/docs/plugins.html#antiflood-plugin" rel="nofollow">AntiFlood Plugin for Swiftmailer</a> 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.  </p>
  
  <p><strong>My second question is: Does the AntiFlood Plugin need an extraordinary long execution time in order to work?</strong> 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?</p>
  
  <pre><code>// 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-&gt;registerPlugin(new Swift_Plugins_AntiFloodPlugin(100));
  
  // And specify a time in seconds to pause for (30 secs)
  $mailer-&gt;registerPlugin(new Swift_Plugins_AntiFloodPlugin(100, 30));
  
  // Continue sending as normal
  for ($lotsOfRecipients as $recipient) {
    ...
  
    $mailer-&gt;send( ... );
  }
  </code></pre>