How to Find Spam Email Generating PHP Files
By simply adding following lines into your php.ini file, you can track down any outgoing spam using PHP. This feature is available since PHP 5.3.0 version.
mail.add_x_header = On
The first line adds a header to all the outgoing email. You can check email headers, X-PHP-Originating-Script will be added that includes UID of the script followed by the filename. Remove this line after you have found the file as it will give out information about your setup and configuration.
mail.log = /var/log/phpmail.log
The second line logs the entire details to a log file.