Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berndengels/laravel-email-exceptions
The Laravel Email Exceptions package, based on Aaron Brigham's Laravel 5.x package (https://github.com/abrigham1/laravel-email-exceptions)
https://github.com/berndengels/laravel-email-exceptions
email exceptions laravel laravel8x laravel9 php php74 php8
Last synced: about 1 month ago
JSON representation
The Laravel Email Exceptions package, based on Aaron Brigham's Laravel 5.x package (https://github.com/abrigham1/laravel-email-exceptions)
- Host: GitHub
- URL: https://github.com/berndengels/laravel-email-exceptions
- Owner: berndengels
- License: mit
- Created: 2020-11-26T02:46:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-03T11:02:48.000Z (over 1 year ago)
- Last Synced: 2024-09-28T20:01:22.484Z (about 2 months ago)
- Topics: email, exceptions, laravel, laravel8x, laravel9, php, php74, php8
- Language: PHP
- Homepage:
- Size: 90.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Laravel Email Exceptions
[![Coverage Status](https://img.shields.io/codecov/c/github/berndengels/laravel-email-exceptions/master.svg)](https://codecov.io/github/berndengels/laravel-email-exceptions?branch=master)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)The "Laravel Email Exceptions" package, based on [Aaron Brigham's](https://github.com/abrigham1/laravel-email-exceptions) Laravel 5.x package (https://github.com/abrigham1/laravel-email-exceptions), is designed to give developers an easy way to email debug information
to themselves whenever an exception is thrown in their application. Information provided by default is:
* Environment
* Exception/Error Remote Url
* Exception/Error Remote IP
* Exception/Error Data Dump of Request
* User Name and Email, if a user is authenticated
* UserAgent of Browser
* Exception/Error Class
* Exception/Error Message
* Exception/Error Code
* File and Line Number
* Stack Trace## Table of Contents
* [Installation](#installation)
* [Configuration](#configuration)
* [Basic Usage](#basic-usage)
* [Basic Config](#basic-config)
* [Throttling](#throttling)
* [Global Throttling](#global-throttling)
* [Advanced Usage](#advanced-usage)
* [Changing the view](#changing-the-view)
* [Adding Arbitrary don't email logic](#adding-arbitrary-dont-email-logic)
* [Gotchas](#gotchas)
* [Bugs and Feedback](#bugs-and-feedback)
* [License](#license)## Installation
You can install this plugin into your laravel 8.x/9.x application using [composer](http://getcomposer.org).Run the following command
```bash
composer require berndengels/laravel-email-exceptions
```
Then in app/Exceptions/Handler.php replace
```php
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
```
with
```php
use Bengels\LaravelEmailExceptions\Exceptions\EmailHandler as ExceptionHandler;
```## Configuration
To publish the config file, view and tests run the following command
```bash
php artisan vendor:publish --provider="Bengels\LaravelEmailExceptions\EmailExceptionsServiceProvider"
```That will create a config file for you in config/laravelEmailExceptions.php and a view in
resources/views/vendor/laravelEmailExceptions/emailExceptions.blade.phpDefault configuration:
```php
'ErrorEmail' => [
'email' => true,
'dontEmail' => [],
'throttle' => false,
'throttleCacheDriver' => env('CACHE_DRIVER', 'file'),
'throttleDurationMinutes' => 5,
'dontThrottle' => [],
'globalThrottle' => true,
'globalThrottleLimit' => 20,
'globalThrottleDurationMinutes' => 30,
'toEmailAddress' => explode(',', env('EXCEPTION_TO_EMAIL_ADDRESS', null)) ?? null,
'fromEmailAddress' => env('EXCEPTION_FROM_EMAIL_ADDRESS', null),
'emailSubject' => env('EXCEPTION_EMAIL_SUBJECT', null)
]
```
In your .env file please set values for:
- EXCEPTION_TO_EMAIL_ADDRESS (one email address or comma separated list of email addresses)
- EXCEPTION_FROM_EMAIL_ADDRESS (string)
- EXCEPTION_EMAIL_SUBJECT (string)* email (bool) - Enable or disable emailing of errors/exceptions
* dontEmail (array) - This works exactly like laravel's $dontReport variable documented here: https://laravel.com/docs/8.x/errors#the-exception-handler under Ignoring Exceptions By Type. Keep in mind also any exceptions under laravel's $dontReport also will not be emailed
* throttle (bool) - Enable or disable throttling of exception emails. Throttling is only performed if its been determined the exact same exception/error has already been emailed by checking the cache. Errors/Exceptions are determined to be unique by exception class + exception message + exception code
* throttleCacheDriver (string) - The cache driver to use for throttling, by default it uses CACHE_DRIVER from your env file
* throttleDurationMinutes (int) - The duration in minutes of the throttle for example if you put 5 and a BadMethodCallException triggers an email if that same exception is thrown again it will not be emailed until 5 minutes have passed
* dontThrottle (array) - This is the same as dontEmail except provide a list of exceptions you do not wish to throttle ever even if throttling is turned on
* globalThrottle (bool) - Enable or disable whether you want to globally throttle the number of emails you can receive of all exception types by this application
* globalThrottleLimit (int) - The the maximum number of emails you want to receive in a given period.
* throttleDurationMinutes (int) - The duration in minutes of the global throttle for example if you put in 30 and have 10 for your globalThrottleLimit when the first email is sent out a 30 minute timer will commence once you reach the 10 email threshold no more emails will go out for that 30 minute period.
* toEmailAddress (string|array) - The email(s) to send the exceptions emails to such as the dev team [email protected]
* fromEmailAddress (string) - The email address these emails should be sent from such as [email protected].
* emailSubject (string) - The subject of email, leave NULL to use default Default Subject: An Exception has been thrown on APP_URL APP_ENV**Note:** the dontReport variable from **app/Exceptions/Handler.php** file will also not be emailed as it's assumed if they are not important enough to log then they also are not important enough to email
**Important:** You must fill out a toEmailAddress and fromEmailAddress or you will not receive emails.
## Basic Usage
#### Basic Config
Update your config values in **config/laravelEmailExceptions.php**
```php
'ErrorEmail' => [
'email' => true,
'dontEmail' => [],
'throttle' => true,
'throttleCacheDriver' => env('CACHE_DRIVER', 'file'),
'throttleDurationMinutes' => 5,
'dontThrottle' => [],
'globalThrottle' => true,
'globalThrottleLimit' => 20,
'globalThrottleDurationMinutes' => 30,
'toEmailAddress' => explode(',', env('EXCEPTION_TO_EMAIL_ADDRESS', '[email protected]')),
'fromEmailAddress' => env('EXCEPTION_FROM_EMAIL_ADDRESS', '[email protected]'),
'emailSubject' => env('EXCEPTION_EMAIL_SUBJECT', null),
]
```#### Throttling
Both throttling and global throttling are put in place in an attempt to prevent spam to the dev team. Throttling works
by creating a unique cache key made from exception class + exception message + exception code. Its aim is to prevent duplicate
exceptions from being reported via email giving the team time to fix them before they are reported again.#### Global Throttling
Global throttling is a similar idea except it's put in place to prevent more then a certain number of emails going out
within a given time period. This should typically only be necessary for an app wide failure ex major portions of the
site are down so many varied types of exceptions are coming in from all directions.## Advanced Usage
### Changing the view
If you published your view using the command above you will be able to change the look of the exception email
by modifying your view in **resources/views/vendor/laravelEmailExceptions/emailException.blade.php**### Adding Arbitrary don't email logic
If you need more complicated logic then just checking instanceof against the thrown exception
there is a convenient hook for adding arbitrary logic to decide if an exception should be emailed.In **app/Exceptions/Handler.php** implement the function appSpecificDontEmail(Exception $exception) ex.
```php