Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 mean sent, i mean sent to the SMTP server.

like image 469
Gary Willoughby Avatar asked Oct 15 '09 10:10

Gary Willoughby


2 Answers

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 on mail(). If mail() returns false, Zend_Mail_Transport_Sendmail throws a Zend_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 in Zend_Mail_Protocol_Smtp. In this case you'll get a Zend_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.

like image 125
Stefan Gehrig Avatar answered Oct 20 '22 09:10

Stefan Gehrig


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.

like image 39
Tomáš Fejfar Avatar answered Oct 20 '22 09:10

Tomáš Fejfar