Question

When you google this error almost all the issues are cuased by empty email addresses or uninterpolated variables. In this case the reported exception cites what appears to be a valid address.

More over it is the only address with the issue; the script emails all other users without issue.

When the error occurred yesterday I manually cleared the field in mySQL and re-entered it as I was worried some stray invisible characters had been pasted in from Outlook but the error recurred today.

Here is the error with the user's email replaced. His email is just firstNameLastName@yahoo.com. Nothing unusual.

PHP Fatal error:  Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [Xxx Yyy <xxxyyy@yahoo.com>] does not comply with RFC 2822, 3.6.2.' in /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/Headers/MailboxHeader.php:308
Stack trace:
#0 /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/Headers/MailboxHeader.php(238): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('Xxx Yyy <xx...')
#1 /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/Headers/MailboxHeader.php(96): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/Headers/MailboxHeader.php(60): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
#4 /home/foo/tax in /home/foo/foo.org/classDBI/Swift-4.1.5/lib/classes/Swift/Mime/Headers/MailboxHeader.php on line 308

The code generating the error, which succeeds except for this one record is

$message = Swift_Message::newInstance()
  ->setSubject("Ticket Report for " . date("n/j/Y"))
  // email => name
  ->setFrom(array('postmaster@' . SITEDOMAIN => ORGNAME . ' Admin'))
  // email => name
  ->setTo(array($u->email => $u->first_name . ' ' . $u->last_name))
  //Give it a body
  ->setBody(strip_tags($email_body))
  //And optionally an alternative body
  ->addPart(nl2br($email_body), 'text/html')
  ;

$transport = new Swift_SmtpTransport(); 
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);

So what should my next step for debugging this be?

Was it helpful?

Solution

As is so often the case a little validation goes a long way and junk data will cause errors.

User had entered as their email "Xxx Yyy <xxxyyy@yahoo.com>" in a spreadsheet and imported to database going around our usual checks for validity. So the error looked like it was complaining about a valid address...

Adding email validation on the way out caught this and we have added appropriate checks against this recurring.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top