请告知如何捕获以下SwiftMailer异常:
[2019-01-13 15:14:45] app.ERROR: Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com [php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution #0]
由于凭据无效而重现此异常,但是我没有运气将其捕获到try-catch块中。
try {
$this->logger->info('Sending email...');
$this->mailer->send($swiftMessage);
} catch (Exception $e) {
$this->logger->error('Email sending fails with Error: '.$e->getMessage());
throw $e;
}
$this->logger->info(__CLASS__.': Email successfully sent');
因此凭据是否有效并不重要-它始终记录成功发送电子邮件的情况。
答案 0 :(得分:0)
捕获\ Error而不是\ Exception。