Problem with Zend_Mail using smtp and attachments

View: New views
3 Messages — Rating Filter:   Alert me  

Problem with Zend_Mail using smtp and attachments

by Dermot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

We're having a bit of a problem here with Zend_Mail when sending mail  
with a pdf attachment (it works fine when there's no attachment).

We get the following warning:

PHP Warning:  Zend_Mail_Protocol_Abstract::require_once(Zend/Mail/
Protocol/Exception.php) [<a href='function.Zend-Mail-Protocol-Abstract-
require-once'>function.Zend-Mail-Protocol-Abstract-require-once</a>]:  
failed to open stream: No such file or directory in /Library/WebServer/
Documents/CBDB/library/Zend/Mail/Protocol/Abstract.php on line 275

followed by ...

PHP Fatal error:  Zend_Mail_Protocol_Abstract::require_once() [<a  
href='function.require'>function.require</a>]: Failed opening required  
'Zend/Mail/Protocol/Exception.php' (include_path='.:../library:../
application/models:../incubator/library:.:../library') in /Library/
WebServer/Documents/CBDB/library/Zend/Mail/Protocol/Abstract.php on  
line 275

and strangely enough, the mail gets sent!


The error doesn't tell alot, so I did a little more digging.  The  
stack trace where the error is thrown is as follows:

#0 /Library/WebServer/Documents/CBDB/library/Zend/Mail/Protocol/
Smtp.php(387): Zend_Mail_Protocol_Abstract->_send('QUIT')
#1 /Library/WebServer/Documents/CBDB/library/Zend/Mail/Transport/
Smtp.php(146): Zend_Mail_Protocol_Smtp->quit()
#2 [internal function]: Zend_Mail_Transport_Smtp->__destruct()
#3 {main}

which would seem to indicate that it's trying to send a smtp QUIT,  
after the connection is closed.

Needless to say, Zend is in the include path.

Anyone know how I should proceed with this?

(ZF 1.5.2, php 5.2.5, and the mail server is the standard OSX postfix  
install).

Any help appreciated,

Dermot.


Re: Problem with Zend_Mail using smtp and attachments

by Dermot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 16 Jul 2008, at 12:36, Dermot Buckley wrote:

> Hi All,
>
> We're having a bit of a problem here with Zend_Mail when sending  
> mail with a pdf attachment (it works fine when there's no attachment).

I've done a bit more digging regarding the above, and I'm stumped :)

It's not related to the attachments as I originally thought, but  
rather it seems to be something to do with the destruction of the  
connection and its related classes.


Here's the sequence of events from what I can see:


The mail is sent, then
Zend_Mail_Protocol_Abstract::_destruct(), calls
Zend_Mail_Protocol_Abstract::_disconnect(), which closes the  
connection to the smtp server (Zend_Mail_Protocol_Abstract::_socket)

Later,

Zend_Mail_Transport_Smtp::_destruct(), has the following code:

        if ($this->_connection instanceof Zend_Mail_Protocol_Smtp) {
            try {
                $this->_connection->quit();
            } catch (Zend_Mail_Protocol_Exception $e) {
            // ignore
            }
            $this->_connection->disconnect();
        }

which calls
Zend_Mail_Protocol_Smtp::quit()

which ultimately tries to send a smtp QUIT over the previously closed  
socket.
This tries to raise the exception I posted (failing to load the  
associated class).



As I said, I'm stumped!

Can anyone shed any light?

Re: Problem with Zend_Mail using smtp and attachments

by Dermot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 16 Jul 2008, at 12:36, Dermot Buckley wrote:

>
>
> We get the following warning:
>
> PHP Warning:  Zend_Mail_Protocol_Abstract::require_once(Zend/Mail/
> Protocol/Exception.php) [<a href='function.Zend-Mail-Protocol-
> Abstract-require-once'>function.Zend-Mail-Protocol-Abstract-require-
> once</a>]: failed to open stream: No such file or directory in /
> Library/WebServer/Documents/CBDB/library/Zend/Mail/Protocol/
> Abstract.php on line 275
>
> followed by ...
>
> PHP Fatal error:  Zend_Mail_Protocol_Abstract::require_once() [<a  
> href='function.require'>function.require</a>]: Failed opening  
> required 'Zend/Mail/Protocol/Exception.php' (include_path='.:../
> library:../application/models:../incubator/library:.:../library')  
> in /Library/WebServer/Documents/CBDB/library/Zend/Mail/Protocol/
> Abstract.php on line 275



Just for the sake of completeness, I'll post the resolution to this  
problem:


For reasons as yet unknown (to me at least), the working directory for  
php changes during object destruction (at least on several of our  
servers here).  A side effect of this is that if you're using relative  
paths in the include path, dynamic loading of php files will fail  
during __destruct calls.

So the fix for me was to change the include path entries to absolute  
paths.  The exception is still thrown in  
Zend_Mail_Protocol_Smtp::quit(), but it is caught and ignored as was  
intended.


Hopefully this will be of help to someone in the future, it cost me  
nearly a day to find.


Dermot.