PHPackages                             rothkj1022/php-error-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. rothkj1022/php-error-handler

ActiveLibrary

rothkj1022/php-error-handler
============================

PHP Error Handler can send you comprehensive error reports via email as well as output to the screen if you so choose.

2.1.2(5mo ago)1812MITPHPPHP ^8.0

Since Jun 9Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/rothkj1022/php-error-handler)[ Packagist](https://packagist.org/packages/rothkj1022/php-error-handler)[ RSS](/packages/rothkj1022-php-error-handler/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (19)Used By (0)

php-error-handler
=================

[](#php-error-handler)

PHP Error Handler can send you comprehensive error reports via email as well as output to the screen if you so choose.

### Features:

[](#features)

- Get notified via email of php errors occurring on your website
- Option to use mysqli or pdo database connection
- Send error reports via email, display to the screen, or both
- Can log all errors in a database, with customizable retention period
- Flood control makes sure you don't get blasted with multiple emails with the same error within a configurable time period
- Send to one or more email recipients, including cc and bcc options
- Only send reports for the error types you choose (errors, warnings, notices, deprecations)

Written by: Kevin Roth -

### License

[](#license)

Released under the MIT license -

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4

### Optional

[](#optional)

- MySQL or other PDO compatible database for logging &amp; flood control features

Installation
------------

[](#installation)

Run the following command in your command line shell in your php project

```
$ composer require rothkj1022/php-error-handler
```

Done.

You may also edit composer.json manually then perform `composer update`:

```
"require": {
    "rothkj1022/php-error-handler": "^2.0.0"
}

```

Getting started
---------------

[](#getting-started)

### Example usage with composer

[](#example-usage-with-composer)

```
require('vendor/autoload.php');
use rothkj1022\PHPErrorHandler;

$errorHandler = new PHPErrorHandler\PHPErrorHandler();
```

### Example usage without composer

[](#example-usage-without-composer)

```
require('src/class.errorhandler.php');
use rothkj1022\PHPErrorHandler;

$errorHandler = new PHPErrorHandler\PHPErrorHandler();
```

### Example with email and database configuration

[](#example-with-email-and-database-configuration)

After including the class file via autoload.php or directly, instantiate the object with a json array like this:

```
$errorHandler = new PHPErrorHandler\PHPErrorHandler([
	'displayErrors' => false,
	'emailErrors' => true,
	'logErrors' => true, //requires database
	'purgeLogTimeout' => '1 DAY', //use mysql date_add interval syntax or set to false
	//'cacheFolder' => '/tmp/', //Folder for caching lookups, such as ip addresses.  Must end with slash.
	'floodControl' => '15 MINUTE', //use mysql date_add interval syntax or set to false
	'database' => [
		/*'driver' => 'mysql', //pdo or mysql
		'hostname' => DB_HOSTNAME,
		'username' => DB_USERNAME,
		'password' => DB_PASSWORD,
		'database' => DB_DATABASE,
		'port' => DB_PORT,
		'charset' => DB_CHARSET,*/
		'driver' => 'pdo', //pdo or mysql
		'dsn' => 'mysql:host='.DB_HOSTNAME.';dbname='.DB_DATABASE.';port='.DB_PORT.';charset=UTF8',
		'username' => DB_USERNAME,
		'password' => DB_PASSWORD
	],
	'email' => [
		'recipients' => [
			'to' => [
				[
					'address' => 'testguy@domain.com',
					'name' => 'Test Guy'
				]
		],
		'from' => [
			'address' => 'noreply@domain.com',
			'name' => 'No Reply'
		]
	]
]);
```

Configuration options
---------------------

[](#configuration-options)

### General

[](#general)

#### displayErrors

[](#displayerrors)

Display error details to screen (not recommended for production)

```
default: false
options: boolean (true / false)

```

#### emailErrors

[](#emailerrors)

Email error reports to configured recipient(s)

```
default: false
options: boolean (true / false)

```

#### logErrors

[](#logerrors)

Log errors to configured database

```
default: false
options: boolean (true / false)

```

#### cacheFolder

[](#cachefolder)

Folder for caching lookups, such as ip addresses

```
default: false
options: string (full path to the cache folder)

```

#### purgeLogInterval

[](#purgeloginterval)

If configured, purges logs in database older than the given interval.

Use mysql date\_add interval syntax or set to false

```
default: '1 DAY'
options: string (date_add interval syntax), false

```

#### floodInterval

[](#floodinterval)

If database is configured, does not send repeat errors via email within set interval

Use mysql date\_add interval syntax or set to false

```
default: '15 MINUTE'
options: string (date_add interval syntax), false

```

### database

[](#database)

Json array of database configuration options

```
default: []
options: array

```

##### MySQL Example:

[](#mysql-example)

```
[
	'driver' => 'mysql',
	'hostname' => 'localhost',
	'username' => 'mysqluser',
	'password' => 'mysqlpass',
	'database' => 'mydatabase',
	'port' => 3306,
	'charset' => 'utf8',
	'table' => 'error_reports'
]

```

##### PDO (with mysql) Example:

[](#pdo-with-mysql-example)

```
[
	'driver' => 'pdo',
	'dsn' => 'mysql:host=localhost;dbname= mydatabase;port=3306;charset=UTF8',
	'username' => 'mysqluser',
	'password' => 'mysqlpass'
]

```

#### driver

[](#driver)

Driver to be used for the database connection

```
default: 'mysql'
options: 'mysql', 'pdo'

```

#### dsn

[](#dsn)

DSN connection string for PDO connections

```
default: ''
options: string (pdo dsn connection string)

```

#### hostname

[](#hostname)

Host name of the database server

```
default: 'localhost'
options: string (server host name)

```

#### username

[](#username)

Database user name

```
default: ''
options: string (db username)

```

#### password

[](#password)

Database password

```
default: ''
options: string, (db password)

```

#### database

[](#database-1)

Database name

```
default: ''
options: string (db name)

```

#### port

[](#port)

Database port

```
default: 3306
options: integer (port number)

```

#### charset

[](#charset)

Database character set

```
default: 'utf8'
options: string (db charset)

```

#### table

[](#table)

Database table name for logging error reports

```
default: 'error_reports'
options: string (db table name)

```

### email

[](#email)

#### recipients

[](#recipients)

Array of to, cc, or bcc types

##### to, cc, &amp; bcc

[](#to-cc--bcc)

Array of contacts (name, address)

##### address

[](#address)

Email address of the contact

```
default: null
options: string (valid email address)

```

##### name

[](#name)

Name of the contact

```
default: null
options: string

```

#### from

[](#from)

##### address

[](#address-1)

Email address of the contact

```
default: null
options: string (valid email address)

```

##### name

[](#name-1)

Name of the contact

```
default: null
options: string

```

#### replyTo

[](#replyto)

##### address

[](#address-2)

Email address of the contact

```
default: null
options: string (valid email address)

```

##### name

[](#name-2)

Name of the contact

```
default: null
options: string

```

#### subject

[](#subject)

```
default: 'PHP Error Report from ' . $_SERVER['SERVER_NAME']
options: string

```

#### PHPMailer

[](#phpmailer)

Json array of email configuration options. See [PHPMailer documentation](https://github.com/PHPMailer/PHPMailer/wiki) for detailed default options.

##### CharSet

[](#charset-1)

```
default: 'utf-8'
options: string

```

##### isSMTP

[](#issmtp)

```
default: false
options: boolean (true, false)

```

##### Host

[](#host)

```
default: 'localhost'
options: string

```

##### Port

[](#port-1)

```
default: 25
options: integer

```

##### SMTPDebug

[](#smtpdebug)

Get debug info for SMTP sending. See [SMTP Debugging](https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging) for more info.

See also PHPMailer [SMTPDebug property](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#property_SMTPDebug) documentation

```
default: 0 (no output)
options: integer

```

##### SMTPAutoTLS

[](#smtpautotls)

Whether to enable TLS encryption automatically if a server supports it, even if `SMTPSecure` is not set to 'tls'.

See also PHPMailer [SMTPAutoTLS property](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#property_SMTPAutoTLS) documentation

```
default: true
options: boolean (true, false)

```

##### SMTPAuth

[](#smtpauth)

Enable SMTP authorization

```
default: false
options: boolean (true, false)

```

##### Username

[](#username-1)

SMTP account username / email address

```
default: ''
options: string

```

##### Password

[](#password-1)

SMTP Password

```
default: ''
options: string

```

##### SMTPSecure

[](#smtpsecure)

Type of encryption used for SMTP sending

```
default: 'tls'
options: string ('ssl', 'tls')

```

##### SMTPOptions

[](#smtpoptions)

See PHPMailer [SMTPOptions property](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#property_SMTPOptions) documentation

```
default: []
options: array

```

###### Example

[](#example)

```
// Disable verification for self-signed ssl certificates
[
	'ssl' => [
		'verify_peer' => false,
		'verify_peer_name' => false,
		'allow_self_signed' => true
	]
]

```

#### errorTypes

[](#errortypes)

Array of PHP error types that you want to be handled

```
default: [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR]
options: array

```

#### warningTypes

[](#warningtypes)

Array of PHP warning types that you want to be handled

```
default: [E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING, E_RECOVERABLE_ERROR]
options: array

```

#### noticeTypes

[](#noticetypes)

Array of PHP warning types that you want to be handled

```
default: [E_NOTICE, E_USER_NOTICE, E_DEPRECATED, E_USER_DEPRECATED]
options: array

```

#### handleErrors

[](#handleerrors)

Whether or not to process errors

```
default: true
options: boolean (true, false)

```

#### handleWarnings

[](#handlewarnings)

Whether or not to process warnings

```
default: true
options: boolean (true, false)

```

#### handleNotices

[](#handlenotices)

Whether or not to process notices

```
default: false
options: boolean (true, false)

```

#### ipinfoToken

[](#ipinfotoken)

Your API token for ipinfo.io if you have one

```
default: '';
options: string

```

### Public methods

[](#public-methods)

 Plugin method Description  mysqlError($errorMsg, $sql, $errfile = null, $errline = 0, $die = false)  Send a MySQL-specific error report, including the query. $errorMsg = the error message to send, usually $mysqli-&gt;error. $sql = the query. $errfile = the file in which the error occurred, called by using \_\_FILE\_\_. $errline = the line of the file on which the error occurred, called by using \_\_LINE\_\_. $die = whether or not to stop processing the script after sending the error. See example below.    sendError($errorMsg, $msgDetails = '', $errfile = null, $errline = 0, $die = false)  Send a custom error report. $errorMsg = the error message to send. $msgDetails = further details regarding your custom error. $errfile = the file in which the error occurred, called by using \_\_FILE\_\_. $errline = the line of the file on which the error occurred, called by using \_\_LINE\_\_. $die = whether or not to stop processing the script after sending the error. See example below.  ##### mysqlError Example:

[](#mysqlerror-example)

```
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);

$sql = "select blah from products limit 3";
$query = $mysqli->query($sql) or $errorHandler->mysqlError($mysqli->error, $sql, __FILE__, __LINE__);

```

##### sendError Example:

[](#senderror-example)

```
$errorHandler->sendError('$myVar is not defined.', 'You should really define that variable.', __FILE__, __LINE__);

```

Changelog
---------

[](#changelog)

### Version 2.0.7

[](#version-207)

- Added config var for ipinfo.io API token
- Fixed flood control

### Version 2.0.6

[](#version-206)

- Updated ip address lookups to fetch with Guzzle for better reliability.
- Added cacheFolder option for caching remote lookups

### Version 2.0.5

[](#version-205)

- Added config var for allowing change of PHPMailer SMTPAutoTLS setting

### Version 2.0.4

[](#version-204)

- Added config vars for allowing change of reply-to address

### Version 2.0.3

[](#version-203)

- Added config vars to disable processing errors, warnings, and notices

### Version 2.0.1 &amp; 2.0.2

[](#version-201--202)

- Fixes for composer integration

### Version 2.0.0

[](#version-200)

- Code overhaul with composer integration
- Added changelog, readme documentation
- Enhancement: added PDO database option

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance70

Regular maintenance activity

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 82.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~160 days

Recently: every ~610 days

Total

18

Last Release

170d ago

PHP version history (3 changes)2.0.0PHP ^5.4 || ^7.0

2.1.0PHP ^5.4 || ^7.0 || ^8.0

2.1.2PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bd167830b02c879a6114bee00b9530318d51241711b8fe6083bfeadde078490?d=identicon)[rothkj1022](/maintainers/rothkj1022)

---

Top Contributors

[![rothkj1022](https://avatars.githubusercontent.com/u/1591839?v=4)](https://github.com/rothkj1022 "rothkj1022 (19 commits)")[![krothapigroup](https://avatars.githubusercontent.com/u/146483151?v=4)](https://github.com/krothapigroup "krothapigroup (4 commits)")

### Embed Badge

![Health badge](/badges/rothkj1022-php-error-handler/health.svg)

```
[![Health](https://phpackages.com/badges/rothkj1022-php-error-handler/health.svg)](https://phpackages.com/packages/rothkj1022-php-error-handler)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[saithink/saiadmin

webman plugin

2709.9k1](/packages/saithink-saiadmin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
