当前位置:Gxlcms > PHP教程 > 通过Email发送php错误的方法示例代码

通过Email发送php错误的方法示例代码

时间:2021-07-01 10:21:17 帮助过:15人阅读

这篇文章主要介绍了通过Email发送PHP错误的方法,实例分析了php错误的读取及通过php发送Email的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了通过Email发送PHP错误的方法。分享给大家供大家参考。具体实现方法如下:

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

以上就是通过Email发送 php错误的方法示例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行