dongyao9762 2015-10-16 06:30
浏览 193
已采纳

Laravel 5向电子邮件发送错误

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: https://github.com/TheMonkeys/laravel-error-emailer That did this for you in Laravel 4.

They have yet to release a Laravel5 update because of the way they changed error handling... which I am also not to familiar with.

I have a few Laravel 5 applications which I need to monitor but I need a more efficient way of doing it besides checking error logs on storage.

Any help would be greatly appreciated. I know there are others out there seeking this information as well.

  • 写回答

7条回答 默认 最新

  • doudihuang7642 2015-10-16 06:52
    关注

    You can do this by catching all the errors in the App\Exceptions\Handler::report(). So in you App/Exceptions/Handler.php add a report function if its not already there.

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(\Exception $e)
    {
        if ($e instanceof \Exception) {
            // emails.exception is the template of your email
            // it will have access to the $error that we are passing below
            Mail::send('emails.exception', ['error' => $e->getMessage()], function ($m) {
                $m->to('your email', 'your name')->subject('your email subject');
            });
        }
    
        return parent::report($e);
    }
    

    If you need more info, refer to laravel documentation form mailer and errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功