访问给定 url 所需的资源,即 /newsletter/send 将可供所有人访问。如果真人点击网址并不重要,因为该页面的内容会很无趣=)
脚本本身将简单地检查是否有邮件要发送,然后从 DB 等中获取所有用户。Newsletter-methology 非常不依赖于 Zend。
不过,您也可以使用 Zend 和 Zend_Mail 轻松完成模板化工作。这就是我在 Zend 中处理电子邮件的方式:
$mail = new Zend_Mail('UTF-8');
$mailView = new Zend_View();
$mailView->setScriptPath(APPLICATION_PATH.'/views/email/');
$mailView->assign('title', $this->_report->getTitle());
$mailView->assign('text', $this->_report->getText());
$mail->addTo($user->getEmail(), $user->getFullnameBySurname());
$mail->setBodyHtml($mailView->render('emailregular.phtml')); // /application/views/email/emailregular.phtml
$mail->setBodyText(strip_tags($mailView->render('emailregular.phtml'))); //might not be the cleanest way...
try {
$mail->send();
$mail->clearRecipients(); // This clears the addTo() for Zend_Mail as in my script i only have one instance of zend_mail open while looping through several users
$this->_log->info('Mail out for user ....');
} catch (Zend_Mail_Transport_Exception $e) {
$this->_log->error('Zend_Mail_Transport_Exception for User('.$user->getid().') - Mails were not accepted for sending: '.$e->getMessage());
} catch (Zend_Mail_Protocol_Exception $e) {
$this->_log->error('Zend_Mail_Protocol_Exception for User('.$user->getid().') - SMTP Sentmail Error: '.$e->getMessage());
} catch (Exception $e) {
$this->_log->error('Unknown Exception for User('.$user->getid().') - SMTP Sentmail Error: '.$e->getMessage());
}
希望这是你要的=)