2016-04-06 11 views
1

Herhangi bir hata olduğunda e-posta adresine posta göndermek istiyorum. Şimdiye kadar geliştirme ortamı üzerinde çalışıyorum. Bu 'u gerçekleştirmek için kodu here'dan kullandım ve bu kodu app/Exceptions/Handler.php'da uyguladım.Mail Laravel'de Hata 5

Bir hata oluştuğunda, ne hata gösterir ne de bir e-posta gönderir.

Benim kod aşağıda:

public function report(Exception $e) 
{ 
    if ($e instanceof \Exception) { 
     //dd($e->getLine()); <-- gives output 
     // emails.exception is the template of your email 
     // it will have access to the $error that we are passing below 
     $mail = Mail::send('emails.error_report', ['content' => $e->getMessage()], function ($m) { 
      $m->to('[email protected]', 'Name')->subject('Error Report'); 
     }); 
     return parent::report($e); 
    } 
    return parent::report($e); 
} 

cevap

0

birkaç saatlik bir araştırmadan sonra, bu nedeni ne olabilir fikir edinmek başarmış. Sanırım, bir hatayla uğraşıyoruz ve bu hatayı ele alırsak, başka bir hata oluşursa ne olur? anlamına gelir, posta işlevi görünüm dosyasında bir hata vardı. zaten bir hata ile çalışırken, daha fazla ele alınamadı.

Answer doğruydu. Benim özel problemimdi. Ama yine de kodun bağlı olandan çok farklı olmamasına rağmen kodu bazı doğaçlamalarla paylaşmak istiyorum.

  public function report(Exception $e) 
    { 
     if ($e instanceof Exception) { 
       // whenever any error occurs, a mail will be sent to desired email. 
       // content variable will contain message that you can send to emails.error_report(or whatever) view. 
       // you can use this variable simply echoing $content. 
       $content = "There was an error occured on Your Website.following are details of Error:<br><br>Message : ".$e->getMessage()."<br>Line : ".$e->getLine()."<br>File : ".$e->getFile().""; 
       $mail_content = [ 
         'content' => $content, 
        ]; 
       // if you want to mail that error message to multiple email addresses put those addresses in $emails array. 
       $emails = array('[email protected]','[email protected]'); 
       $mail = Mail::send('emails.error_report', $mail_content, function ($message) use ($emails) { 
         $message->to($emails, 'Maninder')->subject('Error Report'); 
        }); 
      } 
    return parent::report($e); 
    } 

Kullanımdan kaldırmayı umuyor \ Support \ Facades \ Mail; app/Exceptions/Handler.php dosyasının üstünde.

1 gün boyunca çalışma kodunu kullandıktan sonra, yöneticiye bildirilmek için gerekli olmayan hatalarla ilgili bir sürü posta aldığımı fark ettim. Küçük bir değişiklik yaptıktan sonra aldım, yönetici yalnızca önemli bir hata olduğunda e-posta alacak yeni gelenler için kodlama

if ($e instanceof Exception) { 

Mutlu:

if ($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) { 

yerine: tüm istisnalara bildirilmesini istiyorsanız occurs.though, sen modifikasyon aşağıda yukarıda olduğu gibi kod saklamak veya yapabilirsiniz benim gibi! ;)