PHP PHP自定义错误处理和电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP PHP自定义错误处理和电子邮件相关的知识,希望对你有一定的参考价值。

<?php

// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars)

{
	$email = "
		<p>An error ($number) occurred on line 
		<strong>$line</strong> and in the <strong>file: $file.</strong> 
		<p> $message </p>";
		
	$email .= "<pre>" . print_r($vars, 1) . "</pre>";
	
	$headers = 'Content-type: text/html; charset=iso-8859-1' . "
";
	
	// Email the error to someone...
	error_log($email, 1, 'you@youremail.com', $headers);

	// Make sure that you decide how to respond to errors (on the user's side)
	// Either echo an error message, or kill the entire project. Up to you...
	// The code below ensures that we only "die" if the error was more than
	// just a NOTICE. 
	if ( ($number !== E_NOTICE) && ($number < 2048) ) {
		die('There was an error. Please try again later.');
	}
}

// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');

// Trigger an error... (var doesn't exist)
echo $somevarthatdoesnotexist;

以上是关于PHP PHP自定义错误处理和电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

PHP:自定义错误处理程序 - 处理解析和致命错误

PHP 自定义PHP错误处理程序

PHP解析PHP中的错误和异常处理

通过自定义错误页面处理 PHP / mysql 错误(包括致命错误)

PHP Catch没有捕获自定义异常处理程序的异常

自定义PHP错误处理程序