我不知道为什么我没有在我的控制器中捕获 Swiftmailer 的异常。我做错了什么,或者错过了什么?
在控制器中我有:
try {
$this->get('mailer')->send($email);
}
catch (\Swift_TransportException $e) {
$result = array(
false,
'There was a problem sending email: ' . $e->getMessage()
);
}
它似乎在到达我的代码之前就被 Symfony 捕获了,所以我无法自己处理错误,而是得到了标准的 500 页面Swift_TransportException: Connection could not be established
如果电子邮件无法发送,则无需停止应用程序,因为电子邮件并不重要 - 我只是想发出通知。
也许有一种方法可以禁用 Symfonys 捕获某些异常或某些控制器?
当你这样做时$this->container->get("mailer")->send($email);
如果您打开了假脱机功能,则此时不会发送电子邮件。看http://symfony.com/doc/current/cookbook/email/spool.html http://symfony.com/doc/current/cookbook/email/spool.html
如果您的默认设置为spool: { type: memory }
, the \Swift_TransportException
将在控制器退出后的内核终止阶段抛出。
解决此问题的一种方法是关闭假脱机(但随后您的用户可能必须等待电子邮件发送),或者您可以创建自己的事件侦听器来处理异常。http://symfony.com/doc/current/cookbook/service_container/event_listener.html http://symfony.com/doc/current/cookbook/service_container/event_listener.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)