Skip to content

Commit

Permalink
added enable/disable, parse subject and content, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Funk committed Nov 1, 2012
1 parent e1917e1 commit a1ed65f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -6,8 +6,15 @@ A configurable drop-in customization to email yourself PHP errors encountered in
## Usage

1. drop ```email_php_errors.php``` into ```application/config``` and ```MY_Exceptions.php``` into ```application/core```. If you already have a ```MY_Exceptions.php``` just modify accordingly.
2. Edit the config file with your from email and to email, the subject line, and the message template.
2. Edit the config file with your from email and to email, the subject line, and the message template.

## Change Log

* **1.0.0** - initial release
**1.0.1**

* added enable/disable config item
* parses subject *and* content for short codes

**1.0.0**

* initial release
5 changes: 4 additions & 1 deletion application/config/email_php_errors.php
Expand Up @@ -9,11 +9,14 @@
* @file email_php_errors.php
*/

// to enable, set this to true
$config['email_php_errors'] = false;

$config['php_error_from'] = 'from@from.com';
$config['php_error_to'] = 'to@to.com';
$config['php_error_subject'] = 'PHP Error';

// available shortcodes are {{severity}}, {{message}}, {{filepath}}, {{line}}
$config['php_error_subject'] = 'PHP Error';
$config['php_error_content'] = 'Severity: {{severity}} --> {{message}} File Path: {{filepath}} Line: {{line}}';

/* End of file email_php_errors.php */
Expand Down
62 changes: 45 additions & 17 deletions application/core/MY_Exceptions.php
Expand Up @@ -22,10 +22,10 @@ class MY_Exceptions extends CI_Exceptions {
* extend log_exception to add emailing of php errors.
*
* @access public
* @param mixed $severity
* @param mixed $message
* @param mixed $filepath
* @param mixed $line
* @param string $severity
* @param string $message
* @param string $filepath
* @param int $line
* @return void
*/
function log_exception($severity, $message, $filepath, $line)
Expand All @@ -35,25 +35,53 @@ function log_exception($severity, $message, $filepath, $line)
// this allows different params for different environments
$ci->config->load('email_php_errors');

// set up email with config values
$ci->load->library('email');
$ci->email->from(config_item('php_error_from'));
$ci->email->to(config_item('php_error_to'));
$ci->email->subject(config_item('php_error_subject'));
// if it's enabled
if (config_item('email_php_errors'))
{
// set up email with config values
$ci->load->library('email');
$ci->email->from(config_item('php_error_from'));
$ci->email->to(config_item('php_error_to'));

// set up content
$content = config_item('php_error_content');
// set up subject
$subject = config_item('php_error_subject');
$subject = $this->_replace_short_tags($subject, $severity, $message, $filepath, $line);
$ci->email->subject($subject);

// set up content
$content = config_item('php_error_content');
$content = $this->_replace_short_tags($content, $severity, $message, $filepath, $line);

// set message and send
$ci->email->message($content);
$ci->email->send();
}

// do the rest of the codeigniter stuff
parent::log_exception($severity, $message, $filepath, $line);
}

// --------------------------------------------------------------------------

/**
* replace short tags with values.
*
* @access private
* @param string $content
* @param string $severity
* @param string $message
* @param string $filepath
* @param int $line
* @return string
*/
private function _replace_short_tags($content, $severity, $message, $filepath, $line)
{
$content = str_replace('{{severity}}', $severity, $content);
$content = str_replace('{{message}}', $message, $content);
$content = str_replace('{{filepath}}', $filepath, $content);
$content = str_replace('{{line}}', $line, $content);

// set message and send
$ci->email->message($content);
$ci->email->send();

// do the rest of the codeigniter stuff
parent::log_exception($severity, $message, $filepath, $line);
return $content;
}

// --------------------------------------------------------------------------
Expand Down

0 comments on commit a1ed65f

Please sign in to comment.