views:

182

answers:

2

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.

A: 

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.

Tomáš Fejfar
i mean sent to the SMTP server not check it has been delivered.
Gary Willoughby
Than I guess it's enough that the Zend_Transport_SendMail() doesn't throw an exception ;)
Tomáš Fejfar
+7  A: 

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.

Stefan Gehrig
Sorry I read over your point about sending the email via a STMP server - you can skip point 1 in my answer.
Stefan Gehrig
Very good +1, ;)
daemonfire300