ISN (International Social Networking Services - Interactive Apps and Websites)

Example of function to send out email if error occurs - PHP Scripts


   function reported() 
      $domain = ''; 
      // --------------------------------------------------------------- 
      if( isset($_COOKIE['error']) ) 
        $_COOKIE['error'] = unserialize( $_COOKIE['error'] ); 
        if( in_array($_SERVER['REQUEST_URI'], $_COOKIE['error']) ) 
          return TRUE; 
    $_COOKIE['error'][] = $_SERVER['REQUEST_URI']; 
    $value = serialize( $_COOKIE['error'] ); 
    setcookie( 'error', $value, time() + 24*60*60, '/', './'.$domain, 0 ); 
    unset( $domain, $value ); 
    return FALSE; 
   function error($error='Undefined') 
     if( !reported() ) 
      $to = ''; 
      $subject = "Error type $error has occured on $_SERVER['REQUEST_URI']"; 
      // set the MESSAGE: e-mail 
      $message = " $error has occured on page:\n" 
            ."  //www.{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\n" 
            ."  Referring Page: ".( isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown' )." \n" 
            ."  Time: ".date('r')."\n" 
            ."  From IP: {$_SERVER['REMOTE_ADDR']}\n\n" 
            ."Please Investigate the problem ASAP"; 
      $headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n" 
             ."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n" 
             ."X-Mailer: PHP/".phpversion(); 
      // send the email 
      mail( $to, $subject, $message, $headers ); 
EXAMPLE for a 404 error page. 
error($error='404 Error'); 
By continuing to use this site, you agree to the use of cookies to personalize content and advertisements, to provide social media functionality, to analyze our traffic using Google services like Analytics and Adsense.

Google Adsense and its partners may use your data for advertising personalization and cookies may be used for personalized and non-personalized advertising. How does Google use my data?
Please use the following button to see the list of Google partners as well as all the details regarding cookies.
See detailsI Accept
These cookies are mandatory for the operation of, if you do not accept them please quit this site.
You have the right to refuse cookies and leave the site or to change the parameters.