Check mail sent successfully or not on Laravel 5

I have a function that can send mail to Laravel5 using this

/** * Send Mail from Parts Specification Form */ public function sendMail(Request $request) { $data = $request->all(); $messageBody = $this->getMessageBody($data); Mail::raw($messageBody, function ($message) { $message->from(' yourEmail@domain.com ', 'Learning Laravel'); $message->to(' goper.zosa@gmail.com '); $message->subject('Learning Laravel test email'); }); return redirect()->back(); } /** * Return message body from Parts Specification Form * @param object $data * @return string */ private function getMessageBody($data) { $messageBody = 'dummy dummy dummy dummy'; } 

and sent successfully. But how to check whether it is sent or not? how

 if (Mail::sent == 'error') { echo 'Mail not sent'; } else { echo 'Mail sent successfully.'; } 

I just guess what the code is.

+7
smtp sendmail laravel laravel-5
source share
2 answers

I'm not quite sure this will work, but you can give him a chance

 /** * Send Mail from Parts Specification Form */ public function sendMail(Request $request) { $data = $request->all(); $messageBody = $this->getMessageBody($data); Mail::raw($messageBody, function ($message) { $message->from(' yourEmail@domain.com ', 'Learning Laravel'); $message->to(' goper.zosa@gmail.com '); $message->subject('Learning Laravel test email'); }); // check for failures if (Mail::failures()) { // return response showing failed emails } // otherwise everything is okay ... return redirect()->back(); } 
+10
source share

Hope this helps

 Mail::send(...) if( count(Mail::failures()) > 0 ) { echo "There was one or more failures. They were: <br />"; foreach(Mail::failures as $email_address) { echo " - $email_address <br />"; } } else { echo "No errors, all sent successfully!"; } 

source: http://laravel.io/forum/08-08-2014-how-to-know-if-e-mail-was-sent

+4
source share

All Articles