2014-02-27 22 views
0

我試圖解決使用Swiftmailer一箇舊的應用程序,但我不知道如何解決這個錯誤:Swiftmailer鼻祖字段錯誤

PHP Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [[email protected]] 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('[email protected]') 
    \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 

有關該錯誤的附加信息可以在這裏找到:https://tools.ietf.org/html/rfc2822#section-3.6.2

這裏就是鼻祖字段設置

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'"); 
    } 

注碼!我正在使用一個有效的電子郵件地址

回答

0

我對這個錯誤沒有特別的經驗。但一個快速的谷歌搜索提供了以下兩種選擇:

  1. mailaddress是一個真正的mailaddress? Swiftmailer檢查domaindns檢查等幾件事
  2. 關閉RFC 2822檢查。在我看來不是最好的選擇。

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

+0

我使用的電子郵件地址是一個真正的電子郵件地址。我已經嘗試關閉RFC檢查,但仍然沒有郵件發送沒有qdditional阿帕奇錯誤 – David