Reputation: 59
I am working with Laravel error handling and want to send email from App::error when exception occurs.
Following code is working and I get emails
$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('[email protected]');
$message->to('[email protected]')->subject('Error on '.$details['server']);
});
However, when I change from Mail::send to Mail::later(20, I get following error when exception occures
Error in exception handler: Array to string conversion (View: /app/views/emails/exception.blade.php) in /app/storage/views/1c8e0883061171a30b7f85d86c83370d:8
My email template is as follows
Client: {{$ip}}
Host: {{$host}}
URL: {{$url}}
Exception:
{{$exception}} - This is where the error is
Upvotes: 1
Views: 863
Reputation: 10003
When using Mail::later
, Laravel depends on jeremeamia/super_closure to serialize PHP Closure objects. I suspect your exception is being serialized into an array.
Since you're using $exception
exclusively as a string (not an object), you can fix the problem by stringifying the exception before passing it to Mail::later
by using typecasting:
$data = array('exception' => (string) $exception, 'ip'=> $ip, 'host'=> $host, 'url'=> $url);
Upvotes: 1