title: Not all mails being received by recipients when sent via PHP using Amazon SES
body: <p>I wrote simple PHP (codeigniter) script to send newsletter with Amazon SES. I have ~8000 emails in MySQL table and script which pulls all rows (email addresses), splits it in smaller packages (because of SES limits) and send email via SMTP. I'm using <code>sleep()*</code> and a cronjob which runs every minute. I know that isn’t the best solution but as a concept it works fine. </p>
  
  <p>To allow sending mails with <code>bcc</code>, I have to make sure there is at last one recipient in <code>to</code> field or Amazon SES will not send it. So, my address (<code>news@baulink.rs</code>) is always in <code>to</code> and the other addresses are in <code>bcc</code>. Every iteration puts 8 different addresses in <code>bcc</code> (BTW, is there any better solution for this?). I also have a simple log file which writes every address operated by my application. </p>
  
  <p>As I see, some recipients don’t get the newsletter. Amazon SES returns bounced emails and that works fine, but some addresses doesn't get it at all and there is no any feedback from Amazon SES. These addresses are in my log, which means they are processed by PHP script. Then I just delete that address and insert again in MySQL table and - it works! Some e-mails are parsed from CSV file, some of were inserted manually. I really don't know and can't check with all recipients if they got the newsletter. Do you have any idea what could cause this strange behavior?</p>
  
  <p>I can't figure out what is the problem. </p>
  
  <p>I'm using CodeIgniter and PHPMailer. </p>
  
  <pre><code> public function cronSendMail(){
      $newsletter = $this-&gt;baumodel-&gt;getNewsletter();
  
      if(is_array($newsletter)){
          echo "No job for me!";    
          return;
      }elseif(is_object($newsletter)){ //means there is a newsletter ready for sending                        
          $limit = 104;
          $newsOfset = $newsletter-&gt;news_slanje_ofset;                        
          $noviOfset = $newsOfset+$limit;
  
          $adrese = $this-&gt;baumodel-&gt;getAdresar($limit, $newsOfset); 
          $brojAdresa = count($this-&gt;baumodel-&gt;getSveAdrese()); //number of recipients in whole MySQL table
  
          if($brojAdresa &lt; $newsOfset){ 
              echo "Adrese: ".$brojAdresa;
              echo " Ofset: " .$newsOfset;
              die('Job is finished! ');
          }
  
          $this-&gt;baumodel-&gt;setNewsletterOfset($newsletter-&gt;news_id, $noviOfset);                      
          $emailArray = array();
  
          foreach($adrese as $adr){
              array_push($emailArray, trim($adr['adr_email']));
          }
  
          $newsletterContent = $newsletter-&gt;news_sadrzaj;                                                                                     
          $this-&gt;load-&gt;library('email');
          $this-&gt;email-&gt;clear();                
  
          $maliNiz = array();
          for($i=0; $i&lt;13; $i++){
              //13 times with 2 seconds sleep is ~30-35 seconds of execution time.
              //CronJob runs every minute
              $j=0;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;                           
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;
              $maliNiz[$j] = array_pop($emailArray);
              $j++;                           
  
              $this-&gt;email-&gt;to('news@baulink.rs');
              $this-&gt;email-&gt;bcc($maliNiz); //This is my BCC array of 8 addresses
              $this-&gt;email-&gt;from('office@baulink.rs', 'Baulink Portal');
              $this-&gt;email-&gt;subject('Gradjevinski portal Baulink - Novo na portalu');
              $this-&gt;email-&gt;message($newsletterContent);
              $this-&gt;email-&gt;send();
              //echo $this-&gt;email-&gt;print_debugger();
  
              sleep(2);               
  
              //log file start
              $filepath = APPPATH . 'logs/mail-log-' . date('Y-m-d') . '.php';
              $handle = fopen($filepath, "a+");                                                       
              $currentDateTime = date('d.M.Y H:i:s');
              foreach($maliNiz as $emailAdresa){
                      $infoLog = $emailAdresa . " // ".$currentDateTime . " \n";
                      fwrite($handle, $infoLog);
              }
              fclose($handle);
              //log file end
          }
      }
  }
  </code></pre>