2013-06-11 6 views
13

मैं लैरवेल 4 में नई मेल क्लास का उपयोग कर रहा हूं, क्या कोई यह जानता है कि ईमेल कैसे भेजा गया था या नहीं? कम से कम मेल सफलतापूर्वक एमटीए को सौंप दिया गया है कि ...लार्वेल 4 मेल क्लास, ईमेल कैसे भेजा गया था, यह जानने के लिए कैसे?

+0

हाँ तुम सिर्फ करने के लिए app-> config-> मेल जाएगी और इसमें परिवर्तन का नाटक => true नहीं कर सकते ?? इस तरह आप लॉग – KyleK

उत्तर

11

यदि आप करते हैं

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

जब यह या भेजा गया था नहीं आपको पता चल जाएगा, लेकिन यह बेहतर हो सकता है, क्योंकि SwiftMailer जो करने के लिए जानता है प्राप्तकर्ताओं यह विफल रहा है, लेकिन 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 में आप अब

Mail::failures(); 
+0

में संदेश देख सकते हैं धन्यवाद, लेकिन मुझे केवल पहले भाग की आवश्यकता है, लेकिन उदाहरण के लिए मेरे पास यह प्राप्तकर्ता "ebc @ vd" है, मुझे अभी भी नंबर 1 मिलता है, और यदि मैं प्राप्तकर्ता के लिए 'fdfdfd' का उपयोग करता हूं तो यह लटकता है! मैं मामलों में 0 प्राप्त करना चाहता हूं। मुझे लगता है कि यह लैरवेल कार्यान्वयन के साथ एक समस्या है .. – ebelendez

+0

हाँ, यह अजीब है, इस तरह से लटका नहीं होना चाहिए, लेकिन लैरावेल स्विफ्टमेलर का उपयोग करता है, इसलिए इसमें एक समस्या होनी चाहिए। मेल भेजने के बारे में, कभी-कभी आपको संदेश भेजने के दौरान कोई त्रुटि नहीं मिलती है, क्योंकि एसएमटीपी सर्वर ने संदेश स्वीकार कर लिया है और यह एक ई-मेल वापस भेज देगा कि आपका संदेश डिलीवर नहीं किया गया था। –

+2

बस ध्यान दें कि 4.1 के साथ हम 'विफलता()' :) – seus

1

का उपयोग कर एंटोनियो नहीं जानते हुए भी जो विफल रहा है के बारे में एक अच्छा बिंदु है विफल रही प्राप्तकर्ताओं के लिए उपयोग किया जा सकता है।

वास्तविक प्रश्न सफल हैं हालांकि। आपको परवाह नहीं है कि जितना असफल रहा उतना असफल रहा। यहां कोई असफल होने की जांच करने के लिए एक उदाहरण दिया गया है।

$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; 
संबंधित मुद्दे

 संबंधित मुद्दे