Track email sent via PHP script – cPanel


Track what PHP script sent an email on your cPanel server

There is a patch available from which forces PHP scripts to store the script name and location in the mail headers when using the mail() function. The below instructions will give you the details needed to add this patch to your cPanel server:

1) Log into the server as root via ssh or the console.
Run PHP Code:
mkdir -p /var/cpanel/buildapache/scripts

Create a file called phppost using a text editor like vim and add the following lines:
PHP Code:

PHPVER=`find -type d -iname "php-*"|sed "s/.///g"`
patch -p0 < $PHPVER-mail-header.patch

Save and quit that file.
Run PHP Code:

and now the patch will be automatically applied.

When you receive spam complaints you will now be able to look at the headers of the message and view what script and site these came from. This is extremely useful because PHP runs as nobody unless phpsuexec is enabled and in a virtual environment it can be difficult trying to track down the broken script!


I am a g33k, Linux blogger, developer, student and Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....