我正在使用Laravel错误处理,并希望在发生异常时从App :: error发送电子邮件 .
以下代码正常运行,我收到了电子邮件
$data = array('exception' => $exception,'ip'=>$ip,'host'=>$host,'url'=>$url);
$details=['server'=>$server];
Mail::later(10,'emails.exception', $data, function($message) use($details)
{
$message->from('xxxx@xxxx.com');
$message->to('xxxx@xxxx.com')->subject('Error on '.$details['server']);
});
但是,当我从Mail :: send更改为Mail :: later时(20,出现异常时出现以下错误)
异常处理程序出错:/ app / storage / views / 1c8e0883061171a30b7f85d86c83370d中的数组到字符串转换(查看:/app/views/emails/exception.blade.php):8
我的电子邮件模板如下
Client: {{$ip}}
Host: {{$host}}
URL: {{$url}}
Exception:
{{$exception}} - This is where the error is
1 回答
使用
Mail::later
时,Laravel依赖于jeremeamia/super_closure来序列化PHP Closure对象 . 我怀疑你的异常被序列化为一个数组 .由于您只使用
$exception
作为字符串(不是对象),因此可以通过使用类型转换将异常字符串化为Mail::later
来解决问题: