Laravel Framework

David Carr

Laravel 5.3 send errors to email

Errors in Laravel are logged to files. That’s useful for monitoring when things go wrong. For more real time updates send errors by emailed. This post will explain how do set that up.

First open app/Exceptions/Handler.php find the report method. In this method the exceptions are collected so adding an a mail send call here is ideal. the first param of send is the path to the view file. In this case resources/views/emails/errorreport.blade.php. Next pass the params in an array.

Inside the closure set the to field and the message. 

public function report(Exception $exception)

    Mail::send('emails.errorreport', ['e' => $exception], function($message)

Inside resources/views/errorreport.blade.php I have:

<h3>Error information:</h3>
<p><strong>Date:</strong> {{ date('M d, Y H:iA') }}</p>
<p><strong>Message:</strong> {{ $e->getMessage() }}</p>
<p><strong>Code:</strong> {{ $e->getCode() }}</p>
<p><strong>File:</strong> {{ $e->getFile() }}</p>
<p><strong>Line:</strong> {{ $e->getLine() }}</p>
<h3>Stack trace:</h3>
<pre>{{ $e->getTraceAsString() }}</pre>

Now every time there is an error an email will be sent.

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.