PHP code example of ebrigham1 / cakephp-error-email

1. Go to this page and download the library: Download ebrigham1/cakephp-error-email library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ebrigham1 / cakephp-error-email example snippets


Plugin::load('ErrorEmail', ['bootstrap' => true]);

use Cake\Error\ErrorHandler;

use ErrorEmail\Error\ErrorHandler;

use Cake\Error\Middleware\ErrorHandlerMiddleware;

use ErrorEmail\Middleware\ErrorHandlerMiddleware;

'ErrorEmail' => [
    'email' => false,
    'emailLevels' => ['exception', 'error'],
    'emailDeliveryProfile' => 'default',
    'skipEmail' => [],
    'throttle' => false,
    'throttleCache' => '_error_email_',
    'skipThrottle' => [],
    'toEmailAddress' => null,
    'fromEmailAddress' => null,
    'environment' => null,
    'siteName' => null
],
'Cache' => [
    '_error_email_' => [
        'className' => 'File',
        'prefix' => 'error_email_',
        'path' => CACHE . 'error_emails/',
        'duration' => '+5 minutes'
    ],
],

'ErrorEmail' => [
    'email' => true,
    'skipEmail' => [],
    'throttle' => true,
    'skipThrottle' => [],
    'toEmailAddress' => '[email protected]',
    'fromEmailAddress' => '[email protected]',
    'environment' => 'production',
    'siteName' => 'yoursite.com'
],


namespace App\Traits;

trait EmailThrowableTrait
{
}


namespace App\Error;

use App\Traits\EmailThrowableTrait;
use ErrorEmail\Error\ErrorHandler as ErrorEmailErrorHandler;

class ErrorHandler extends ErrorEmailErrorHandler
{
    use EmailThrowableTrait;
}


namespace App\Middleware;

use App\Traits\EmailThrowableTrait;
use ErrorEmail\Middleware\ErrorHandlerMiddleware as ErrorEmailErrorHandlerMiddleware;

class ErrorHandlerMiddleware extends ErrorEmailErrorHandlerMiddleware
{
    use EmailThrowableTrait;
}

use Cake\Error\ErrorHandler; // Or use ErrorEmail\Error\ErrorHandler;

use App\Error\ErrorHandler;

use Cake\Error\Middleware\ErrorHandlerMiddleware; // Or use ErrorEmail\Middleware\ErrorHandlerMiddleware;

use App\Middleware\ErrorHandlerMiddleware;

protected function _appSpecificSkipEmail($throwable)
{
    // Add any logic here to skip emailing throwables that }

protected function _appSpecificSkipThrottle($throwable)
{
    // Add any logic here to skip throttling throwables that 

protected function _setupEmail(\Cake\Mailer\Email $email, $throwable)
{
   // Add logic here to pick the email template, layout,
   // set the to address, from address, viewVars, ect.
   // Make sure to return your email object at the end of the function
   // so the plugin can send the email.
   return $email;
}