我写的服务是在ZF2发送电子邮件,不幸的是有时候我得到例外:
Zend\Mail\Protocol\Exception\RuntimeException
Could not read from [smtp server]
堆栈跟踪的一部分:
#0 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php(339): Zend\Mail\Protocol\AbstractProtocol->_receive(300)
#1 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(353): Zend\Mail\Protocol\AbstractProtocol->_expect(221, 300)
#2 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(389): Zend\Mail\Protocol\Smtp->quit()
#3 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(380): Zend\Mail\Protocol\Smtp->_disconnect()
#4 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(152): Zend\Mail\Protocol\Smtp->disconnect()
#5 /homez.157/pastydol/www/module/Page/src/Page/Controller/OrderController.php(144): Zend\Mail\Transport\Smtp->__destruct()
我想抓住这个例外,在服务中,我发送电子邮件:
try {
$transport->send($mail);
} catch(\Zend\Mail\Exception $e) {
return -1;
}
catch(\Exception $ex) {
return -1;
}
但它不起作用,我仍然得到这些例外。