Swift Mailer is an robust object oriented library written in PHP5 with lot of useful features. It can be used with any PHP application developed in PHP5. Symfony, Typo3 framework as well as many other open source framework uses this library. The error i am talking about seems to be a common error and lot of people talking on the web about it. I personally encountered this error with Symfony framework when i was trying to send an email to user after registration. The script thrown following error:

Fatal error: Uncaught exception ‘Swift_RfcComplianceException’ with message ‘Address in mailbox given [] does not comply with RFC 2822, 3.6.2.’ in

The exception itself says there is something wrong in email address fields such as From, Sender or Reply-To fields. Swift Mailer strictly follow RFC standard to avoid emails being caught by spam checker tools. There are following reason can lead to this error.

  • Incorrect email address format in to,from or reply-to fields
  • Email address or host does not exist
  • From email address should be valid working email address
  • Not fully qualified domain name used in from email address

To fix this error check above settings in you script and fix accordingly. You may need to check RFC standard to fix this error. If still does not fix error you can disable email address RFC standard checking code in swift mailer script. Obviously this is not recommended but some time developer need to apply fix temporarily.

Before applying please check Swift Mailer documentation on how to set To,From,Cc, Bcc, Reply To fields correctly in Swift Mailer.

How To Disable RFC Standard Check

Go to swiftmailer\classes\Swift\Mime\Headers folder and open MailboxHeader.php file in editor. Go to line number 304 and comment throw exception line as specified below.

For Symfony users: swift mailer library can be found in vendor folder.

private function _assertValidAddress($address)
{
  if (!preg_match('/^' . $this->getGrammar('addr-spec') . '$/D',
    $address))
  {
    //throw new Swift_RfcComplianceException(
    //  'Address in mailbox given [' . $address .
    //  '] does not comply with RFC 2822, 3.6.2.'
    //  );
  }
}

The error should be disappear now.

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.