How to Mail Contents of an Error Page

Login or register to post comments
3 replies [Last post]
Offline
Joined: 11/19/2009

Hi Forum,

I want to, if an PHP Error occurs, mail the Contens of the PHP Error page to a specifix EMail Adress.

Is ist possible to mail the contents of the qcubed generated error page.

Is it possible?

thanx ion advance

strophi

Steven Warren's picture
Offline
Joined: 11/06/2008

I do this in all my projects. What I do is modify /assets/_core/php/error_page.php.

<?php
   
// Generate the Error Dump
   
if (!ob_get_level()) ob_start();
    require(
__DOCROOT__ . __PHP_ASSETS__ . '/error_dump.php');

   
// Do We Log???
   
if (defined('ERROR_LOG_PATH') && ERROR_LOG_PATH && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) {
       
// Log to File in ERROR_LOG_PATH
       
$strContents = ob_get_contents();

       
QApplication::MakeDirectory(ERROR_LOG_PATH, 0777);
       
$strFileName = ERROR_LOG_PATH . '/' . date('Y-m-d-H-i-s-' . rand(100,999)) . '.html';
       
file_put_contents($strFileName, $strContents);      
        @
chmod($strFileName, 0666);
       
// Send email to Steve with error
       
$objMessage = new QEmailMessage;
       
$objMessage->From = 'website@mysite.com';
       
$objMessage->To = 'dev@mywebsite.com';
       
$objMessage->Subject = 'Website Error' ;
       
$objMessage->HtmlBody = $strContents;
       
AFCEmailServer::Send($objMessage);
    }
?>

AFCEmailServer is just the standard QEmailServer with some initialization.

Offline
Joined: 11/11/2008

Mmmm you could do that Steven. But I guess you can also use the friendly_error_page.php page. This way you can post a friendly message to your users and mail the full error to your own inbox.

That's how we do it... I don't like customers seeing big useless error messages :-)

Steven Warren's picture
Offline
Joined: 11/06/2008

Users still get the friendly error message, I am intercepting the logging function so whatever gets written to the log also gets emailed to me irregardless of whether Friendly Error Messages is set to true or false.