Laravel 5 Send Errors to Email

前端 未结 9 683
野的像风
野的像风 2021-02-03 10:45

I am trying to figure out how I can send errors to my email in Laravel 5. I haven\'t had much luck finding any good resources.

There used to be good packages like: http

9条回答
  •  猫巷女王i
    2021-02-03 11:08

    Here is the solution for Laravel 5.3

    #file:   /app/Exceptions/Handler.php
    
    public function report(Exception $e)
    {
        if($this->shouldReport($e)){
    
            \Mail::send(
                ['html' => 'error.emails.exception'],
                ['content' => $data['content']],
                function ($m) {
                    $m->from(['myemail@from.com']);
                    $m->to(['myemail@to.com']);
                    $m->subject('Crash Report');
                }
            );
        }
    
        parent::report($e);
    }
    
    • You need to create the exception.blade.php file in /resources/views/emails
    • I advise you to use this content, to make the email look the same as Laravel's error page.

提交回复
热议问题