使用 Zend_Mail 时如何验证邮件已发送?
我正在使用 Zend 框架发送邮件。一旦配置完成并编写代码,一切都归结为一个调用:
$Mail->send($Transport)
我如何检查这封邮件是否已正确发送?我在某处读到 Zend Mail 抛出异常,但其他人说有时情况并非如此。
使用 Zend_Mail 时确保邮件正确发送的防弹编程方法是什么?
编辑:当我的意思是发送时,我的意思是发送到 SMTP 服务器。
I am using the Zend framework to send mail. Once the config is done and the code written it all boils down to one call:
$Mail->send($Transport)
How can i check that this mail has been sent correctly? I read somewhere that Zend Mail throws an exception but other people have said this is sometimes not the case.
What's the bulletproof programmatic way to ensure mail has been sent properly when using Zend_Mail?
EDIT: When i mean sent, i mean sent to the SMTP server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,如果发送过程中出现问题,
Zend_Mail
会抛出异常 - 但这很大程度上取决于所使用的Zend_Mail_Transport_*
。这里有两个选项:
Zend_Mail_Transport_Sendmail
(默认传输)依赖于mail()
。如果mail()
返回false
,Zend_Mail_Transport_Sendmail
会抛出Zend_Mail_Transport_Exception
(无法发送邮件)。返回值本身不太可靠。这是手册中关于返回值的说法:<块引用>
如果邮件被成功接受投递,则返回 TRUE,否则返回 FALSE。
<块引用>
需要注意的是,邮件被接受投递并不意味着邮件实际上会到达预期目的地。
Zend_Mail_Transport_Smtp
使用封装在Zend_Mail_Protocol_Smtp
中的 SMTP 协议发送电子邮件。在这种情况下,每当违反 SMTP 协议(例如在不提供发件人地址的情况下发送邮件)或 STMP 服务器报告错误或连接超时时,您都会收到Zend_Mail_Protocol_Exception
。因此,如果与 STMP 服务器通信时没有引发异常,您可以确定远程服务器至少接受了您的电子邮件。
Generally
Zend_Mail
will throw an exception if there is something wrong going on on the send-process - but this strongly depends on theZend_Mail_Transport_*
being used.You have two options here:
Zend_Mail_Transport_Sendmail
(the default transport) relies onmail()
. Ifmail()
returnsfalse
,Zend_Mail_Transport_Sendmail
throws aZend_Mail_Transport_Exception
(Unable to send mail). The return value itself is not very reliable. This is what the manual says about the return value:Zend_Mail_Transport_Smtp
sends the email using the SMTP protocol that's encapsulated inZend_Mail_Protocol_Smtp
. In this case you'll get aZend_Mail_Protocol_Exception
whenever something either violates the SMTP protocol (sending mail without giving a sender's address e.g.) or the STMP server reports an error or the connection times out.So if no exception is thrown when talking to the STMP server, you can be sure that the remote server at least accepted your email.
我想不是。如果“发送”失败,您会收到异常。但这只是检查 send() 函数是否正常工作。这并不意味着邮件已发送。
我想确保邮件送达的唯一方法是在邮件中插入确认码链接并让用户单击它。
I guess it's not. If "sending" failed you get an exception. But that's only a check, that the send() function worked properly. It doesn't mean the mail got send.
I guess the only way to ensude the mail was delivered is to insert a confirmation code link inte the mail and make user click it.