Logging PHP scripts sending mail

Today I will tell you how you can keep a log of scripts that send mail methods PHP.
This is useful if you have settled on a server spammer and you do not know where to find him, because own way to run scripts by default do not fall into / var / log / syslog or /var/log/mail.log.

In PHP since version 5.3 add the logging is quite simple.
Open the php.ini file


And add 2 lines:

mail.add_x_header adds a header to all outgoing messages.
mail.log specifies the path to the log file of the scripts, mailing and headers. Make sure that the file was available to wash down the Web server (usually the user www-data).

Now in message headers will be inserted as follows:


Where 0 this UID, and testmail.php – is the name of the script file.

In the log /var/log/php.mail.log will fall more extensive information: