Log error messages to the web server’s error log and send them to an email address.
<?php // Send error message to the server log if error connecting to the database if (!mysqli_connect(“localhost”,“bad_user”,“bad_password”,“my_db”)) { error_log(“Failed to connect to database!”, 0); } // Send email to administrator if we run out of FOO if (!($foo = allocate_new_foo())) { error_log(“Oh no! We are out of FOOs!”, 1, “[email protected]”); } ?> |
The error_log() function sends an error message to a log, a file, or an email account.
error_log(message, type, destination, headers); |
Parameter |
Description |
message |
Required. Specifies the error message to be logged. |
type |
Optional. Determines where the error message should be sent. Possible values are: 0 – Default. The message is sent to PHP’s system logger, using the OS’s system logging mechanism or a file, based on the error_log configuration in php.ini. 1 – The message is sent by email to the address specified in the destination parameter. 2 – No longer in use (available only in PHP 3). 3 – The message is appended to the file specified in the destination. 4 – The message is sent directly to the SAPI logging handler. |
destination |
Optional. Specifies the destination for the error message, based on the value of the |
headers |
Optional. Used only when the type parameter is set to 1. Specifies additional headers, such as From, Cc, and Bcc. Multiple headers should be separated by a CRLF (\r\n). |
Return Value: |
Returns TRUE if successful and FALSE if it fails. |
PHP Version: |
4.0+ |
Binary Safe: |
No |
PHP Changelog: |
In PHP 5.2.7, the value 4 was introduced for the type parameter. |