Log mails send via php mail function

Here is a simple script which can log necessary information regarding mails send via php mail() function.

Create a file /usr/local/bin/sendmail-logger with the following code inside and correct the file ownership/permission to root/755

logger -p mail.info sendmail-logger: site=${HTTP_HOST}, 
client=${REMOTE_ADDR}, script=${SCRIPT_NAME}, pwd=${PWD}, uid=${UID}, 
/usr/sbin/sendmail -t -i $*

Create a file /usr/local/bin/php_set_envs.php with the following code inside


Edit the following values in php.ini

sendmail_path = /usr/local/bin/sendmail-logger 
auto_prepend_file = /usr/local/bin/php_set_envs.php

The log information will be written on /var/log/maillog

root@ [~]# grep sendmail-logger /var/log/maillog 
Nov 26 04:47:03 cpanel1 logger: sendmail-logger: site=, 
client=, script=/testmail.php, pwd=/usr/local/apache/htdocs, 
uid=99, user=nobody
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: