How to verify a mail has been sent when using Zend_Mail?
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 m开发者_开发问答ean sent, i mean sent to the SMTP server.
Generally Zend_Mail
will throw an exception if there is something wrong going on on the send-process - but this strongly depends on the Zend_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:Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
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.
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.
精彩评论