The below code is an example of providing some debug information by both email and logging the information to a file in “/var/logs/”.
define("CURRENT_FILE", "thisfile.php"); define("LOG_FILE_LOCATION", "/var/log/"); function log_file($error1, $error2, $file) { $ok = true; // $file = "logile.txt"; if ($fh = fopen($file, 'a')) { $ok = true; $conf = "$error1 - $error2\n"; } else { $ok = false; $conf = ""; } if (fwrite($fh, $conf)) { $ok = true; } else { $ok = false; } if (fclose($fh)) { $ok = true; } else { $ok = false; } } function error_notifications($error) { /* Usage - print error_notifications("" . CURRENT_FILE . " - FUNCTION-NAME - ERROR\n"); */ print "$error"; $datetime = date('d-m-y--H-i'); $name = "System Error Notification"; $email = "root@something"; $text = " ========================= System Error Notification ========================= An Error has occurd with the system, the error is listed below:-\n Date And Time Stamp - $datetime\n $error Regards, The System. "; $sendthisto = "user@domain.com, root"; if (mail($sendthisto, 'System Error Notification', $text, 'From: ' . $name . ' ')) { print "Error Notification Email Sent\n"; log_file("$datetime - Email Sent", "$error", "".LOG_FILE_LOCATION."Custom_Error_Notifications.txt"); } else { print "can not email, writing error to log file\n"; if (log_file("$datetime - Email Failed", "$error", "".LOG_FILE_LOCATION."Custom_Error_Notifications.txt") == true ) { Print "completed ok"; } else { print "$datetime - BIG FUCKING PROBLEMS WITH SYSTEM LOGGING!!!"; } } }