2013-06-11 23 views
13

私はLaravel 4で新しいメールクラスを使用していますが、誰かが電子メールが送信されたかどうかを確認する方法を知っていますか?少なくとも、メールが正常に... MTAに引き渡されたことLaravel 4メールクラス、メールが送信されたかどうかを知る方法?

+0

うんCONFIG->メールや変更は=>真のふり>あなただけのAPP-に行くカント??あなたはログのメッセージを見ることができます – KyleK

答えて

11

あなたが行う場合

if (! Mail::send(array('text' => 'view'), $data, $callback)) 
{ 
    return View::make('errors.sendMail'); 
} 

それが送信されたりされなかったとき、あなたが知っているだろうが、ではSwiftMailerはWICHを知っているので、それは、より良いかもしれません受信者は、それが失敗したが、Laravelは、私たちは、その情報を得るのを助けるために、関連するパラメータを暴露されていません。

/** 
* Send the given Message like it would be sent in a mail client. 
* 
* All recipients (with the exception of Bcc) will be able to see the other 
* recipients this message was sent to. 
* 
* Recipient/sender data will be retrieved from the Message object. 
* 
* The return value is the number of recipients who were accepted for 
* delivery. 
* 
* @param Swift_Mime_Message $message 
* @param array    $failedRecipients An array of failures by-reference 
* 
* @return integer 
*/ 
public function send(Swift_Mime_Message $message, &$failedRecipients = null) 
{ 
    $failedRecipients = (array) $failedRecipients; 

    if (!$this->_transport->isStarted()) { 
     $this->_transport->start(); 
    } 

    $sent = 0; 

    try { 
     $sent = $this->_transport->send($message, $failedRecipients); 
    } catch (Swift_RfcComplianceException $e) { 
     foreach ($message->getTo() as $address => $name) { 
      $failedRecipients[] = $address; 
     } 
    } 

    return $sent; 
} 

しかし、あなたはLaravelのメーラーを拡張し、新しいクラスのメソッドを送信するために、その機能($ failedRecipients)を追加することができます。 4.1では

EDIT

あなたは今、アントニオが失敗したわからない程度の良い点を有し

Mail::failures(); 
+0

ありがとう、しかし私はちょうど最初の部分が必要ですが、例えば私はこの受信者 "ebc @ vd"を持っている場合、私はまだ番号1を取得し、受信者のために 'fdfdfd'私は0の場合を取得したいと思います。私はそのLaravelの実装とprobleと思う。 – ebelendez

+0

奇妙です、この方法でハングアップすべきではありませんが、LaravelはSwiftMailerを使用するので、それは問題でなければなりません。メールの送信については、SMTPサーバーがメッセージを受け入れたためにメッセージを送信している間にエラーが発生しないことがあり、メッセージが配信されなかったことを知らせる電子メールが返されることがあります。 –

+2

4.1で、 'failedRecipients 'を' failures() 'で得ることができることに注意してください:) – seus

1

を使用して、失敗した受信者へのアクセス権を持つことができます。

本当の質問は成功です。 ANYが失敗したように失敗したものは気にしません。 これは、失敗したかどうかを確認するための例です。

$count=0; 
$success_count = \Mail::send(array('email.html', 'email.text'), $data, function(\Illuminate\Mail\Message $message) use ($user,&$count) 
{ 
    $message->from($user->primary_email, $user->attributes->first.' '.$user->attributes->last); 
    // send a copy to me 
    $message->to('[email protected]', 'Example')->subject('Example Email'); 
    $count++ 
    // send a copy to sender 
    $message->cc($user->primary_email); 
    $count++ 
} 
if($success_count < $count){ 
    throw new Exception('Failed to send one or more emails.'); 
} 
1
if(count(Mail::failures()) > 0){ 
       //$errors = 'Failed to send password reset email, please try again.'; 
       $message = "Email not send"; 
      } 
return $message; 
関連する問題