Laravel exception notifier will send an email of of the error along with the stack trace to the chosen recipients.
Table of contents: - About - Requirements - Installation Instructions - Screenshots - File Tree - License, (*2)
Laravel exception notifier will send an email of the error along with the stack trace to the chosen recipients. This Package includes all necessary traits, views, configs, and Mailers for email notifications upon your applications exceptions. You can customize who send to, cc to, bcc to, enable/disable, and custom subject or default subject based on environment. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, 7, 8, 9, and 10., (*3)
Get the errors and fix them before the client even reports them, that's why this exists!, (*4)
From your projects root folder in terminal run:, (*5)
Laravel 9-10 use:, (*6)
composer require jeremykenedy/laravel-exception-notifier
Laravel 7-8 use:, (*7)
composer require jeremykenedy/laravel-exception-notifier:2.2.0
Laravel 6 and below use:, (*8)
composer require jeremykenedy/laravel-exception-notifier:1.2.0
Register the package, (*9)
* Laravel 5.5 and up
Uses package auto discovery feature, no need to edit the config/app.php
file., (*10)
config/app.php
under providers
with the following:jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier::class,
php artisan vendor:publish --tag=laravelexceptionnotifier
php artisan vendor:publish --force --tag=laravelexceptionnotifier
App\Exceptions\Handler.php
include the additional following classes in the head:use App\Mail\ExceptionOccurred; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; use Throwable;
use App\Mail\ExceptionOccured; use Illuminate\Support\Facades\Log; use Mail; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
App\Exceptions\Handler.php
sendEmail()
method:/** * Sends an email upon exception. */ public function sendEmail(Throwable $exception): void { try { $content = [ 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'url' => request()->url(), 'body' => request()->all(), 'ip' => request()->ip(), ]; Mail::send(new ExceptionOccurred($content)); } catch (Throwable $exception) { Log::error($exception); } }
register()
method:/** * Register the exception handling callbacks for the application. */ public function register(): void { $this->reportable(function (Throwable $e) { $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); if ($enableEmailExceptions) { $this->sendEmail($e); } }); }
report()
method with:/** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Throwable $exception * * @return void */ public function report(Throwable $exception) { $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); if ($enableEmailExceptions === '') { $enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault'); } if ($enableEmailExceptions && $this->shouldReport($exception)) { $this->sendEmail($exception); } parent::report($exception); }
sendEmail()
:/** * Sends an email upon exception. * * @param \Throwable $exception * * @return void */ public function sendEmail(Throwable $exception) { try { $e = FlattenException::create($exception); $handler = new SymfonyExceptionHandler(); $html = $handler->getHtml($e); Mail::send(new ExceptionOccured($html)); } catch (Throwable $exception) { Log::error($exception); } }
Configure your email settings in the .env
file., (*11)
Add the following (optional) settings to your .env
file and enter your settings:, (*12)
config/exception.php
EMAIL_EXCEPTION_ENABLED=false EMAIL_EXCEPTION_FROM="${MAIL_FROM_ADDRESS}" EMAIL_EXCEPTION_TO='email1@gmail.com, email2@gmail.com' EMAIL_EXCEPTION_CC='' EMAIL_EXCEPTION_BCC='' EMAIL_EXCEPTION_SUBJECT=''
, (*13)
โโโ laravel-exception-notifier โโโ .gitignore โโโ LICENSE โโโ composer.json โโโ readme.md โโโ src โโโ .env.example โโโ App โย ย โโโ Mail โย ย โย ย โโโ ExceptionOccurred.php โย ย โโโ Traits โย ย โโโ ExceptionNotificationHandlerTrait.php โโโ LaravelExceptionNotifier.php โโโ config โย ย โโโ exceptions.php โโโ resources โโโ views โโโ emails โโโ exception.blade.php
brew install tree
tree -a -I '.git|node_modules|vendor|storage|tests'
Laravel-Exception-Notifier | A Laravel Exceptions Email Notification Package is open-sourced software licensed under the MIT license, (*14)