I’m using the code below for logging and sending error to my e-mail, but i don’t know why $content variable does not contain anything when i check my emails. Is this a scope mistake? or I’m doing something wrong?
ob_start();
set_error_handler('cs_handler', E_ALL);
//a lot includes and method calls here
function cs_handler($errno, $errstr, $errfile, $errline)
{
$content = ob_get();
mail(...., 'Error Happend: '.$content);
}
One issue is that you’ll need to call
ob_start()again, after flushing the buffer, if you want multiple errors-per-page to work properly. Could this be the problem? Are you getting one email with content, followed by others without?Another issue you might be having is that you’re calling
mail()with 2 arguments, when it expects 3 (address, subject, content). You probably want something like:Note that the following works as expected: