Laravel Mail ::以后的错误处理

时间:2014-12-11 20:12:31

标签: email laravel

我正在处理Laravel错误处理,并希望在发生异常时从App ::发送电子邮件。

以下代码正常运行,我收到了电子邮件

$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:8

中的数组到字符串转换(查看:/app/views/emails/exception.blade.php)

我的电子邮件模板如下

Client: {{$ip}}
Host: {{$host}}
URL: {{$url}}
Exception:
{{$exception}} - This is where the error is

1 个答案:

答案 0 :(得分:0)

使用Mail::later时,Laravel依赖于jeremeamia/super_closure来序列化PHP Closure对象。我怀疑你的异常被序列化为一个数组。

由于您将$exception专门用作字符串(不是对象),因此您可以通过在将>传递给Mail::later之前对异常进行字符串处理来解决问题通过使用类型转换:

$data = array('exception' => (string) $exception, 'ip'=> $ip, 'host'=> $host, 'url'=> $url);