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

Posted

tags:

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

Refer here for a full overview: http://net.tutsplus.com/tutorials/php/quick-tip-email-error-logs-to-yourself-with-php/
  1. <?php
  2.  
  3. // Our custom error handler
  4. function nettuts_error_handler($number, $message, $file, $line, $vars)
  5.  
  6. {
  7. $email = "
  8. <p>An error ($number) occurred on line
  9. <strong>$line</strong> and in the <strong>file: $file.</strong>
  10. <p> $message </p>";
  11.  
  12. $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  13.  
  14. $headers = 'Content-type: text/html; charset=iso-8859-1' . "
  15. ";
  16.  
  17. // Email the error to someone...
  18. error_log($email, 1, '[email protected]', $headers);
  19.  
  20. // Make sure that you decide how to respond to errors (on the user's side)
  21. // Either echo an error message, or kill the entire project. Up to you...
  22. // The code below ensures that we only "die" if the error was more than
  23. // just a NOTICE.
  24. if ( ($number !== E_NOTICE) && ($number < 2048) ) {
  25. die('There was an error. Please try again later.');
  26. }
  27. }
  28.  
  29. // We should use our custom function to handle errors.
  30. set_error_handler('nettuts_error_handler');
  31.  
  32. // Trigger an error... (var doesn't exist)
  33. echo $somevarthatdoesnotexist;

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

在python 3.6中处理自定义编码时遇到类型错误

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

php 一个自定义的try..catch包装器代码片段,用于执行模型函数,使其成为一个单行函数调用

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

PHP 异常处理

php异常处理