title: Sending emails to multiple subscribers with the Zend Framework
body: <p>I think I must be doing something wrong here because my code only sent an email to the last subscriber in the table. When I log the array of subscribers, its obvious that there are more than one that it is trying to send to. I think the problem has to do with trying to batch them together...What is the best way for me to do this? I'm trying to create one message, with an attachment, then send address each one individually, and send them all out as one batched process. Here's my code:</p>
  
  <pre><code>    $subscribersManager = new DD_Subscribers_Manager();
      $subscribers = $subscribersManager-&gt;getAllSubscribers();
  
  
      $subject = $form-&gt;getElement('subject')-&gt;getValue();
      $body = $form-&gt;getElement('body')-&gt;getValue();
      $filename = $form-&gt;getElement('bulletin')-&gt;getValue();
      $filepath = Zend_Registry::get('rootDir') . '/public/downloads/archive/' . $filename;
  
      $config = array('ssl' =&gt; 'tls', 'port' =&gt; 587, 'auth' =&gt; 'login', 'username' =&gt; 'fake@email.com', 'password' =&gt; 'password');
      $smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
  
      foreach ($subscribers as $subscriber) {
          $message = new Zend_Mail('utf-8');
          $message-&gt;setFrom('fake@email.com', 'My Fake Mailing List')
                  -&gt;addTo($subscriber-&gt;email)
                  -&gt;setSubject($subject)
                  -&gt;setBodyText($body);
          $attachment = $message-&gt;createAttachment(file_get_contents($filepath));
          $attachment-&gt;type = 'application/pdf';
          $attachment-&gt;filename = $filename;
      }
      $message-&gt;send($smtpConnection);
  </code></pre>