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:
$subscribersManager = new DD_Subscribers_Manager();
$subscribers = $subscribersManager->getAllSubscribers();
$subject = $form->getElement('subject')->getValue();
$body = $form->getElement('body')->getValue();
$filename = $form->getElement('bulletin')->getValue();
$filepath = Zend_Registry::get('rootDir') . '/public/downloads/archive/' . $filename;
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => '[email protected]', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
foreach ($subscribers as $subscriber) {
$message = new Zend_Mail('utf-8');
$message->setFrom('[email protected]', 'My Fake Mailing List')
->addTo($subscriber->email)
->setSubject($subject)
->setBodyText($body);
$attachment = $message->createAttachment(file_get_contents($filepath));
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
}
$message->send($smtpConnection);