|
|
|
|
|
|
| |
|
<?php
//***************************************************************
//** title : Error mailing logging facility
//**
//** file : error.php
//**
//** story : When your site is live you never want people to see
//** php errors no matter what. Sometimes this is possible
//** though because your host might upgrade PHP or MySQL
//** or something else can go bad. The usual advice given
//** is to have error_reporting(0) on the live sites. But
//** then you will never get to know that an error is there.
//**
//** I use a different approach here. I set error reporting
//** to E_ALL (that is report all errors) but I have
//** over-ridden the error handler to construct a nice
//** error report and mail it to me. The application
//** continues, and if the error was not major, the user
//** will never get to notice anything. You on the other
//** side though will know that something has gone wrong
//** and you'll run to fix it.
//**
//** Customize the $to and $from variables, include this
//** file and enjoy.
//**
//** You are going to get something like this:
//**
//** Date : December 3, 2005, 3:55:12 am
//** Server : example.com
//** Error No: 8
//** On file : /home/example/public_html/temp/error.php
//** On line : 35
//** Error : Use of undefined constant bar - assumed 'bar'
//** IP : 87.203.242.37
//** Host : athedsl-12355.otenet.gr
//** Method : GET
//** Vars :
//** name => test
//** age = 55
//**
//**
//** author : Ioannis Cherouvim
//** web : http://cherouvim.com
//** date : 2005-12-03
//***************************************************************
error_reporting(E_ALL);
function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
$ret[] = "Date : " . date("F j, Y, g:i:s a");
$ret[] = "Server : " . $errcontext['_SERVER']['SERVER_NAME'];
$ret[] = "Error No: $errno";
$ret[] = "On file : $errfile";
$ret[] = "On line : $errline";
$ret[] = "Error : $errstr";
$ret[] = "IP : " . $errcontext['_SERVER']['REMOTE_ADDR'];
$ret[] = "Host : " . gethostbyaddr($errcontext['_SERVER']['REMOTE_ADDR']);
$ret[] = "Method : " . $errcontext['_SERVER']['REQUEST_METHOD'];
$ret[] = "Vars :";
foreach($errcontext['_REQUEST'] as $key=>$value)
$ret[] = " $key => $value";
$error = "";
foreach($ret as $line)
$error .= "$line\n";
$to = "example@yahoo.com";
$from = "Error Catcher <errors@example.com>";
$headers = "To: $to\r\n";
$headers .= "From: $from\r\n";
mail($to, "Error on " . $errcontext['_SERVER']['SERVER_NAME'], $error, $headers);
}
$old_error_handler = set_error_handler("errorHandler");
//do something stupid to produce an error.
//it's for testing purposes, please remove
$foo = $bar;
?> | | |
|
| Example of function to send out email if error occurs Categories : PHP, Email, Debugging, Errors and Logging | | | DB Connection Function with error handling and email failure notices Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging | | | Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network, Email, PHP, PHP Classes | | | error_log -- send an error message somewhere Categories : PHP, PHP Functions, Errors and Logging | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | PHPRecommend v1.0 - "Recommend this page to a friend" script written in
PHP. Easy to install Categories : PHP, URLs, Complete Programs, Email, Site Planning | | | imap_sort Categories : IMAP, Email, PHP, PHP Functions | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | PHP port of Matt Wrights FormMail.pl WWW form to e-mail gateway. Categories : Email, Complete Programs, Environment Variables, PHP | | | Ping a Server and run a command to fix it if it is down Categories : PHP, Errors and Logging, Regexps | | | making links from text Categories : PHP, Regexps, Email | | | HTTP Basic Authentication via POP3. Categories : Authentication, HTTP, Email, PHP | | | imap_subscribe -- Subscribe to a mailbox Categories : PHP, PHP Functions, IMAP, Email | | | [PHP5] PHP Debugger and Helper Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML | | | How to specify the From field with the mail() function. Categories : PHP, Email | |
|
|