0

I am trying to fix an old application that uses Swiftmailer, but I have no idea how to fix this error:

PHP Fatal error:  Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [mymail@yahoo.be] does not comply with RFC 2822, 3.6.2.' in /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:308\nStack trace:
    \n#0 /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(238): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('mymaik@yaho...')
    \n#1 /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(96): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
    \n#2 /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(60): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
    \n#3 /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(581): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
    \n#4 /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/cl in /opt/lampp/htdocs/sptoolkit/spt/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php on line 308, referer: http://localhost:8080/sptoolkit/spt/campaigns/?c=9&responses=true

Additional information about the error can be found here: https://www.rfc-editor.org/rfc/rfc2822#section-3.6.2

Here is the code where the originator fields are set

 if ( ! isset ( $relay_host ) AND ! isset ( $relay_username ) AND ! isset ( $relay_password ) ) {
        //parse out the domain from the recipient email address
        $domain_parts = explode ( "@", $current_target_email_address );
        $domain = $domain_parts[1];

    //get MX record for the destination
    getmxrr ( $domain, $mxhosts );

    //
    //create the transport
    if(isset($ssl) && $ssl == "no"){
        $transport = Swift_SmtpTransport::newInstance ( $mxhosts[0], 25 );    
    }else{
        $transport = Swift_SmtpTransport::newInstance ( $mxhosts[0], 25, 'tls' );    
    }
    
}
//Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance ( $transport );

    //To use the ArrayLogger
    $logger = new Swift_Plugins_Loggers_ArrayLogger();
    $mailer -> registerPlugin ( new Swift_Plugins_LoggerPlugin ( $logger ) );

    //Create a message
    $message = Swift_Message::newInstance ( $subject )
            -> setSubject ( $subject )
            -> setFrom ( array ( $sender_email => $sender_friendly ) )
            -> setReplyTo ( $reply_to )
            -> setTo ( array ( $current_target_email_address => $fname . ' ' . $lname ) )
            -> setContentType ( $content_type )
            -> setBody ( $message )
    ;

    //specify that the message has been attempted
    mysql_query ( "UPDATE campaigns_responses SET sent = 1 WHERE response_id = '$current_response_id'" );

    //Send the message
    $mailer -> send ( $message, $failures );

    //store logs in database
    $mail_log = $logger -> dump ();
    $mail_log = nl2br ( htmlentities ( $mail_log ) );
    mysql_query ( "UPDATE campaigns_responses SET response_log='$mail_log' WHERE response_id = '$current_response_id'" );

    //get current datetime
    $sent_time = date ( 'Y-m-d H:i:s' );

    //specify that message is sent and timestamp it
    mysql_query ( "UPDATE campaigns_responses SET sent = 2, sent_time = '$sent_time' WHERE response_id = '$current_response_id'" );

    //specify if there was a failure
    if ( count ( $failures ) > 0 ) {
        mysql_query ( "UPDATE campaigns_responses SET sent = 3 WHERE response_id = '$current_response_id'" );
    }

Note! I am using a valid email address

Community
  • 1
  • 1
David
  • 965
  • 3
  • 12
  • 24

1 Answers1

0

I've no experience in particular with this error. But a quick Google search give met the following two options:

  1. Is the mailaddress a real mailaddress? Swiftmailer check for several things like domaindns checks
  2. Switch off RFC 2822 check. In my opinion not the best option.

https://github.com/swiftmailer/swiftmailer/issues/382

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Simon Blok
  • 66
  • 4
  • The email address I am using is a real email adress. I have already tried turning off RFC check, but still no mails where send out with no qdditional apache errors – David Feb 27 '14 at 13:59