从Zend Framework项目发送简报

时间:2012-06-18 02:47:09

标签: php zend-framework cron newsletter

我有一个使用版本1.10.8和Doctrine 1.2.4的Zend Framework项目。我使用Zend_Auth和Zend_Acl,其中action是资源。我最近添加了时事通讯功能,并想知道我将如何一起玩。这是我第一次做真正的时事通讯和Zend。

所以我的第一种方法是使用php脚本连接到db获取模板,获取订阅者的姓名和电子邮件。解析模板以供用户自定义并发送。我将使用swiftMailer。所以我会设置一个cron作业来为每个句点调用该文件。

现在我担心的是ACL。如果脚本在Zend之外(即我的项目)并且点击Zend动作(url)执行所有的东西系统如何验证自己(我的意思是系统运行cron的cron) php文件)?

使用ZF的另一种方法是什么?感谢

1 个答案:

答案 0 :(得分:2)

所有人都可以访问访问给定网址所需的资源,即/ newsletter / send。真正的人打网址并不重要,因为该网页的内容会非常无趣=)

脚本本身只会检查是否有要发送的邮件,然后从数据库中获取所有用户等.Zend中的Newsletter-methology非常不可靠。

你也可以使用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());
  }

希望这就是你所要求的=)