【问题标题】:Laravel Mail::later in error handlingLaravel Mail::later 错误处理
【发布时间】:2014-12-13 07:39:38
【问题描述】:

我正在处理 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:8 中的数组到字符串转换(视图:/app/views/emails/exception.blade.php)

我的邮件模板如下

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

【问题讨论】:

  • $server 变量是什么?

标签: email laravel


【解决方案1】:

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

由于您将$exception 专门用作字符串(而不是对象),您可以通过使用类型转换将异常传递给Mail::later 来解决问题: p>

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

【讨论】:

  • 这解决了我的问题,但我注意到即使使用 Mail::later,我也会得到 7 秒的响应时间,而如果我禁用邮件部分,我会在一秒钟内恢复!
  • 没关系,我没有实现任何队列。我想一旦我实现了 beanstalkd,它将在以后处理发送
猜你喜欢
  • 1970-01-01
  • 2013-10-07
  • 2015-03-09
  • 1970-01-01
  • 2013-12-08
  • 2018-07-02
  • 2014-11-27
  • 2018-08-01
  • 2017-12-09
相关资源
最近更新 更多