Detectar errores con PHP y enviarlos por Email


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. // funcion de errores personalizado
  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.  
  9. $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  10.  
  11. $headers = 'Content-type: text/html; charset=iso-8859-1' . "
  12. ";
  13.  
  14. // enviar log de errores a un Email
  15. error_log($email, 1, '[email protected]', $headers);
  16.  
  17. // Si es un error demasiado critico, pararlo.
  18. if ( ($number !== E_NOTICE) && ($number < 2048) ) {
  19. die("There was an error. Please try again later.");
  20. }
  21. }
  22.  
  23. // declaramos cual sera la funcion que se ejecutara cuando ocurra un error
  24. set_error_handler('nettuts_error_handler');
  25.  
  26. // realizando un error con una variable no existente
  27. echo $somevarthatdoesnotexist;

URL: http://craftyman.net/errores-con-php-enviarlos-email/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.