2011-08-09 22 views
2

我想這個代碼(從http://swiftmailer.org/docs/sending.html):

require_once 'lib/swift_required.php'; 

//Create the Transport 
$transport = Swift_SmtpTransport::newInstance('localhost', 25); 

//Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

//Create a message 
$message = Swift_Message::newInstance('Wonderful Subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setBody('Here is the message itself') 
    ; 

//Send the message 
$failedRecipients = array(); 
$numSent = 0; 
$to = array('[email protected]', '[email protected]' => 'A name'); 

foreach ($to as $address => $name) 
{ 
    $message->setTo(array($address => $name)); 
    $numSent += $this->send($message, $failedRecipients); 
} 

printf("Sent %d messages\n", $numSent); 

的問題是,如果我發送了一封電子郵件給一個壞域swiftmailer認識到它作爲一個正確發送電子郵件和$failedRecipients是空的。在我的郵箱中,我已發回失敗通知。

爲什麼Swiftmailer無法將此郵件識別爲失敗,並且不會填充$failedRecipientsArray

回答

3

Swiftmailer只負責將電子郵件轉交給郵件服務器。其他的一切都與Swiftmailer無關。

您得到的是退回消息,並且您需要自行處理它們,因爲電子郵件本身實際上是一個語法郵件地址,並未被第一個服務器拒絕。

這btw是任何其他郵件庫,甚至是PHP mail函數的情況。您可能正在尋找反彈處理應用程序或代碼。

相關:Bounce Email handling with PHP?

+1

沒錯。如果郵件服務器*首先接受郵件,SwiftMailer(或任何其他庫)就無能爲力。 –