Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel 5中邮寄错误_Php_Laravel 5 - Fatal编程技术网

Php 在Laravel 5中邮寄错误

Php 在Laravel 5中邮寄错误,php,laravel-5,Php,Laravel 5,每当发生任何类型的错误时,我都想向电子邮件地址发送邮件。到目前为止,我一直致力于开发环境。要做到这一点 我使用了来自的代码,并在app/Exceptions/Handler.php中实现了该代码 发生错误时,它既不显示错误,也不发送电子邮件 我的代码如下: public function report(Exception $e) { if ($e instanceof \Exception) { //dd($e->getLine()); <-- gives

每当发生任何类型的错误时,我都想向电子邮件地址发送邮件。到目前为止,我一直致力于开发环境。要做到这一点 我使用了来自的代码,并在
app/Exceptions/Handler.php
中实现了该代码

发生错误时,它既不显示错误,也不发送电子邮件

我的代码如下:

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('mail@domain.com', 'Name')->subject('Error Report');
        });
        return parent::report($e);
     }
     return parent::report($e);
}
公共职能报告(例外$e)
{
如果($e instanceof\Exception){
//dd($e->getLine());$e->getMessage()],函数($m){
$m->to($m)mail@domain.com“,”名称“)->主题(“错误报告”);
});
返回父::报告($e);
}
返回父::报告($e);
}

经过几个小时的研究,我终于弄明白了这背后的原因。我认为,我们已经在处理一个错误了,在处理这个错误的同时,如果发生另一个错误会发生什么?意思是,我在邮件函数视图文件中出错。已在处理错误时无法进一步处理

所以答案是正确的。这是我的特殊问题。但我还是想分享一些即兴创作的代码,尽管代码与链接线程没有太大区别

         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('mail1@domain.com','mail2@gmail.com');
                $mail = Mail::send('emails.error_report', $mail_content, function ($message) use ($emails) {
                        $message->to($emails, 'Maninder')->subject('Error Report');
                    });
            }
    return parent::report($e);
    }
而不是:

if ($e instanceof Exception) {

很高兴为像我这样的新手编写代码!;)

经过几个小时的研究,我终于弄明白了这背后的原因。我认为,我们已经在处理一个错误了,在处理这个错误的同时,如果发生另一个错误会发生什么?意思是,我在邮件函数视图文件中出错。已在处理错误时无法进一步处理

所以答案是正确的。这是我的特殊问题。但我还是想分享一些即兴创作的代码,尽管代码与链接线程没有太大区别

         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('mail1@domain.com','mail2@gmail.com');
                $mail = Mail::send('emails.error_report', $mail_content, function ($message) use ($emails) {
                        $message->to($emails, 'Maninder')->subject('Error Report');
                    });
            }
    return parent::report($e);
    }
而不是:

if ($e instanceof Exception) {
很高兴为像我这样的新手编写代码!;)