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条)

报告相同问题?

悬赏问题

  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 C++行情软件的tick数据如何高效的合成K线
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。
  • ¥20 在easyX库下编写C语言扑克游戏跑的快,能实现简单的人机对战