我想我在這裏必須做錯事,因爲我的代碼只發送一封電子郵件給表中的最後一個用戶。當我登錄訂閱者數組時,顯然有多個訂閱者試圖發送。我認爲這個問題與嘗試將它們批處理在一起......對我來說這樣做的最好方法是什麼?我試圖用附件創建一條消息,然後分別發送每個地址的地址,並將它們作爲一個批處理進程發送出去。這裏是我的代碼:用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);