我想我在这里必须做错事,因为我的代码只发送一封电子邮件给表中的最后一个用户。当我登录订阅者数组时,显然有多个订阅者试图发送。我认为这个问题与尝试将它们批处理在一起......对我来说这样做的最好方法是什么?我试图用附件创建一条消息,然后分别发送每个地址的地址,并将它们作为一个批处理进程发送出去。这里是我的代码:用Zend Framework向多个用户发送电子邮件
$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);