Kaah
Kaah

Reputation: 955

Is there any good way logging which PHP script is sending emails via PHPMailer?

I have an issue with an unknown PHP script being used to send spam. The site uses PHPMailer which in turn uses sendmail.

How can I log which PHP scripts are sending emails with PHPMailer (and its contents)?

It would have been easy to use mail.log = /var/log/phpmail.log in php.ini but it does not work if the site uses PHPMailer?

Upvotes: 1

Views: 129

Answers (1)

Christian Gollhardt
Christian Gollhardt

Reputation: 17004

You can use the function debug_backtrace() in the send() Method of your PHPMailer:

http://php.net/manual/de/function.debug-backtrace.php

Here you can do the Logging you want (I recommend logging to file)

Note: It is not good practise to edit library files. Maybe you want to extend a class from PHPMailer, make here your additional Logic, and use this.

class MyPhpMailer extends PHPMailer {
    public function send() {
        $callinfo = print_r(debug_backtrace(), true);
        //Logging $callinfo...
        parent::send();
    }
}

Upvotes: 2

Related Questions