By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

send error_log() message to email

Odisey
P: 14
Hello,
I am attempting to send an error_log() message to my email. I don't see any mistakes - yet it is not sending the email.... Any ideas?

Expand|Select|Wrap|Line Numbers
  1. <?php #Script 6.2
  2.  
  3. //Flag variable for site status:
  4.  
  5. $live = TRUE;   // Test output switching status from TRUE; to FALSE;
  6.  
  7. //Email error
  8.  
  9. $email='odisey@odisey.com';
  10.  
  11.  
  12. // Create the error handler
  13.  
  14. function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars)  {
  15.  
  16. global $live, $email;
  17.  
  18. //Build the error message
  19.  
  20. $message = "An error occurred in script '$e_file' on line $e_line: $e_message\n";
  21.  
  22. //Append $e_vars to the $message
  23.  
  24. $message .= print_r($e_vars, 1);
  25.  
  26. if ($live) {//Don't show the error
  27.  
  28.              error_log($message, 1, $email); //Sends email
  29.  
  30.              echo '<div class="error">A system error occurred. We apologize for the inconvenience.  An email has been sent to administrator!</div><br />';
  31.         } else { //Development (Print the error)
  32.  
  33.       echo '<div class="error">' . $message . '</div><br />';
  34.  }
  35.  
  36. } //End of my error handler() definition
  37.  
  38. //Use my error handler
  39.  
  40. set_error_handler ('my_error_handler');
  41. ?>
  42.  
May 15 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Changed the title to better reflect the thread contents.

I don't see a mail() call in there anywhere. Where's the code that sends the email?

Is it not sending the email... or are you just not receiving it? PHP's mail() function only returns an error if it fails to send the email. If you're trying to send an email from your computer, try sending it to yourusername@localhost (if you're running a *n?x system), then open up a terminal window and type 'mail'.
May 15 '07 #2

Odisey
P: 14
Changed the title to better reflect the thread contents.

I don't see a mail() call in there anywhere. Where's the code that sends the email?
OK - I am just learning here. I added a mail() with the error $msg attached and it worked. The original code I got from the book though is as above. I was under the impression that the error_log() function would act as the mail() function in this case and send the email to $email.

Is that true?
May 15 '07 #3

Motoma
Expert 2.5K+
P: 3,235
OK - I am just learning here. I added a mail() with the error $msg attached and it worked. The original code I got from the book though is as above. I was under the impression that the error_log() function would act as the mail() function in this case and send the email to $email.

Is that true?
According to the documentation, error log is supposed to send email. I am not sure why your original code did not work. Perhaps the scope of the error_log's email function is restricted to the scope of the machine it is running on, as most *nix OSs have a locally handled email subsystem.

Regardless, I am glad it is working for you now. Welcome to The Scripts.
May 15 '07 #4

Odisey
P: 14
According to the documentation, error log is supposed to send email. I am not sure why your original code did not work. Perhaps the scope of the error_log's email function is restricted to the scope of the machine it is running on, as most *nix OSs have a locally handled email subsystem.

Regardless, I am glad it is working for you now. Welcome to The Scripts.
UPDATE: I have PHP 5 - MySQL 5 Apache/1.3.33 Server. I tested mail() and it sent the $msg. Then I reverted to error_log() and it sent the message.

...???...

Not sure what happened. It takes 5 - 10 mins to get the message from the server, but it sends.

THX - I will enjoy sharing ideas and helping out.
May 15 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.