我嘗試了幾種方法,但沒有工作,其中包括一個在StackOverFlow -> Swiftmailer TransportException get uncaught by try catch block。與Swiftmailer捕獲塊異常不工作
我需要捕捉,可以在我上課的時候在控制檯上運行誰運行類Swiftmailer的實例來發送電子郵件
/**
* @throws Be msut catch swiftmailer exception Swift_TransportException because ->setTo($send_to) containt '' (not valid email sender)
* But not catch my code.
*/
$transport = \Swift_SmtpTransport::newInstance()
->setHost($settings['smtp_host'])
->setPort($settings['smtp_port'])
->setEncryption($settings['smtp_security'])
->setUsername($settings['smtp_user'])
->setPassword($settings['smtp_pass']);
$mailer = \Swift_Mailer::newInstance($transport);
echo "Verify code\n";
try {
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom(array($settings['smtp_mail_sender'] => $settings['smtp_name_sender']))
->setTo($send_to)
->setBody($msg);
$result = $mailer->send($message);
} catch (\Swift_TransportException $Ste) {
echo "EROORRRRRRRRRRRRRRRRRRRR\n\n\n";
}
顯示錯誤的塊產生的異常
php -q cprsyncbackup.php -option param
No llegue
PHP Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:348
Stack trace:
#0 /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(263): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('')
#1 /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(106): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(63): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/li in /Volumes/iDatos/abkrim/ownCloudTDC/tamainut/desarrollo/cprsync/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php on line 348
代碼拋出'Swift_RfcComplianceException'但漁獲'Swift_TransportException'。後者是否延伸前者? –