473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

send error_log() message to email

Odisey
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
4 3431
pbmods
5,821 Expert 4TB
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
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
3,237 Expert 2GB
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
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

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

Similar topics

0
by: Wayno | last post by:
Hoping someone can help me out with this problem. First problem, is I am unable to view my php error log. In my php.ini I have my log in /var/www/logs/php_error_log. However, it has remained empty....
11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
0
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after...
2
by: Erwin Moller | last post by:
Hi Group, I cannot log errors for some reason. Situation: PHP 5.0 ISAPI on W2000 IIS 5.0 In php.ini: error_reporting = E_ALL log_errors = On
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
1
by: mydejamail | last post by:
My PHP setup is not updating the error_log, I have checked all the error logging related settings and they have all been set. The script is also crashing inexplicably. Whenever I call a specific...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
5
by: August Karlstrom | last post by:
Hi, I'm looking for a function that *returns* a human readable string representation of an array rather than prints it so I can use it with the error_log procedure. Any clues? August
1
by: beary | last post by:
Using php 5 I have access to my own php.ini file on the server I want to send any and all php errors to an email address I tried changing the line error_log = error_log to error_log = ("PHP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.