CodeIgniter Forums
Error Handling - send message to site admin - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Error Handling - send message to site admin (/thread-20884.html)



Error Handling - send message to site admin - El Forum - 07-24-2009

[eluser]jdav3579[/eluser]
Hi,
I am new to error handling and CI, I am trying to determine if when an error occurs is it possible for code igniter not only to log the problem as PHP does, but to also send the error to the site admin as an email?
If this is possible is it difficult and can anyone point me in the direction to start.

Kind regards
John


Error Handling - send message to site admin - El Forum - 07-24-2009

[eluser]exodus7[/eluser]
Hi John,

You need to be a little more specific - what type of error?


Error Handling - send message to site admin - El Forum - 07-24-2009

[eluser]jdav3579[/eluser]
Hi thanks for your reply. Basically I want to capture any errors that the site generates and mail them to me.
In a non-CI site, I would do something like:

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
$msg="error level: {$errno} {$errstr}";
mail('[email protected]','Site has errored',$msg);
}

set_error_handler("myErrorHandler");

This way rather than outputing the problems to the users browser, it sends me an email instead.


In some of my code, I may also use the following:
trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);

The above is not my code but modified examples off PHP.net just as an example of what I am trying to achieve.
I was wondering if I can easily modify code igniter to mail any errors to me.

Cheers
John