2009年5月4日星期一

[fw-core] Zend_Mail

Hi,
 
I used Zend_Mail with sendmail transport class and everything works smoothly inside an action of Zend_Controller.
I then wanted to switch to Smtp transport class and things goes wrong. The mail is correctly sent but it seems that when doing the __destruct function, the smtp transport class wanted to send a "QUIT" message over the socket which is no more a ressource.
In the Zend_Mail_Protocol_Abstract::_send function, the socket is test to be a ressource and the result is false (the reason why, i don't know), thus, it tries to include the "Zend/Mail/Protocol/Exception.php" file. At this point, I have a Fatal Error saying it can't find the file. This file exist and apache has access to it. What is weird is that the include path given with the error is empty while it should contains path (if not the whole site would have not work). Why the include path is empty at this point, i don't know.
 
If I remove the require_once and replace the throw new Zend_Mail_Protocol_Exception with a simple Exception, i got this exception but with no stack frame, so it's difficult to trace.
 
What I supposed is that the destructor is executed by the garbage collector at the end of the script, the socket has been destroyed prior to the call to __destruct and the include path is empty at this stage because the base directory changed to root directory and my relative included path are no more resolved.
Anyways, throwing an exception in a desctructor is not recommended and lead to a fatal error if thrown at the end of the script.
 
To solve this, i call the __destruct function at the end of the _sendMail() function just after having send the mail. I know this may have side effects if the transport class is reused.
 
Any one with the same issue ?
 
Sébastien Crocquesel

没有评论: