Zend_Mail 发送邮件后提示 Fatal Error

这实际上是由于 PHP 不允许在析构函数中抛出异常造成的,关于这个 issue 我已经提交到 issues 上:

http://framework.zend.com/issues/browse/ZF-2534

暂时没有想到好的解决方法。通常执行到析构函数时,邮件已经正确发出。所以最不济的方法就是用try…catch… 捕获异常,并忽略掉。

如下:

public function __destruct()
{

     try

    {
         if ($this->_connection instanceof Zend_Mail_Protocol_Smtp)

        {

            $this->_connection->quit();

            $this->_connection->disconnect();

         }

    catch(Zend_Exception $e)

    {

    }
}

Leave a comment

Your email address will not be published. Required fields are marked *