I am using ext.yii-mail.YiiMail class for sending emails in Yii.
It works fine as long as email/smtp server is up and running. but if its unreachable/down I get a 500 internal server error and exception thrown is never caught.
here are logs from application.log
2013/07/01 18:11:21 [error] [php] <-> fsockopen(): unable to connect to tls://smtp.server.com:465 (Connection timed out) (/protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/StreamBuffer.php:233)
Stack trace:
#0 /protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize()
#1 /protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Mailer.php(74): Swift_SmtpTransport->start()
I am using the following code and even though the exception is generated in try block it is never caught and I get a 500 internal server error.
$message->view = 'test';
$message->subject = "Test Email";
$message->setBody(array(), 'text/html');
try
{
Yii::app()->mail->send($message);
}
catch (Exception $exc)
{
Yii::log("email sending failed due to error: " . $exc->getMessage());
}