[SOLVED] Swift_RfcComplianceException not handled by Email
I've got my "sendTo()" function is a try block, to trap invalid e-mails, however it still does not catch the exception, even though they match 100%??
This code is similar to Newsletters.php
Code:
...
// Deactivate invalid addresses
try
{
$objEmail->sendTo($arrRecipient);
}
catch (Swift_RfcComplianceException $e)
{
$_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
}
// Rejected recipients
if ($objEmail->hasFailures())
{
$_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
}
...
with an invalid e-mail like the one below, it does NOT get trapped by the exception. Is it a try block too deep, or something?
Code:
Fatal error: Uncaught exception Swift_RfcComplianceException with message Address in mailbox given [wrongtime32431&%#^@] does not comply with RFC 2822, 3.6.2. thrown in system/modules/core/vendor/swiftmailer/classes/Swift/Mime/Headers/MailboxHeader.php on line 352
#0 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/Headers/MailboxHeader.php(264): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('wrongtime32431&...')
#1 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/Headers/MailboxHeader.php(108): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/Headers/MailboxHeader.php(65): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
#4 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/SimpleHeaderSet.php(70): Swift_Mime_SimpleHeaderFactory->createMailboxHeader('To', Array)
#5 system/modules/core/vendor/swiftmailer/classes/Swift/Mime/SimpleMessage.php(324): Swift_Mime_SimpleHeaderSet->addMailboxHeader('To', Array)
#6 system/modules/core/library/Contao/Email.php(426): Swift_Mime_SimpleMessage->setTo(Array)
#7 system/modules/calendar_invites/classes/EventInvites.php(436): Contao\Email->sendTo('wrongtime32431&...')
#8 system/modules/calendar_invites/classes/EventInvites.php(202): Contao\EventInvites->sendInvitation(Object(Contao\Email), Object(Contao\Database\Mysql\Result), 'wrongtime32431&...', ' HP Feel the...', 'send(Object(Contao\DC_Table))
#10 contao/main.php(129): Contao\Backend->getBackendModule('calendar')
#11 contao/main.php(271): Main->run()
#12 {main}
Re: Swift_RfcComplianceException not handled by Email.php
Might be a namespace issue, try putting a \ infront of the class so it's \Swift_RfcComplianceException. If your code is in the Contao namespace it will be looking for Contao\Swift_RfcComplianceException.
I don't know if that's the case here because i'm not sure what namespace your code is and and what namespace Swift_RfcComplianceException is in, but I know that when i've tried to catch exceptions before in Contao 3 I had to use \Exception.
Re: Swift_RfcComplianceException not handled by Email.php
That was it! Thanks for the help. I guess the Newsletter.php has a bug in it too.