PHP – overloading system function, debugging?

Today I needed to find a file where is called PHP system function, it was to find the place where the email is send. The problem was that the system is huge and messy. There is no wrapper (PHPMailer or something) which will be sending the emails. You will need to install APD, it?s a PECL extension. After that you can overload the mail function and with debug_backtrace get the stacktrace.

// code of the override function
$code=<<<'CODE' $trace=debug_backtrace(); $caller=array_shift($trace); echo 'mail() called by '.$caller['function'] if (isset($caller['class'])) echo 'in '.$caller['class']; CODE; //install override override_function('mail', '$to,$subject,$msg,$hdrs,$params', $code); [/sourcecode]

Leave a Reply

Your email address will not be published. Required fields are marked *