我们可以挂钩PHP mail()函数[关闭]

Can we hook PHP mail() function, Like when the mail function call we call our function before sending emails. I need to perform some action between mail function calling and sending.

Simple, create your own function that has the same parameters as mail() and call mail() at the end of your function code. You can call it like xmail($reciever, $subject, $msg, $headers) and instead of using mail(), you are using your own function.

function xmail($reciever, $subject, $msg, $headers){
    //Do stuff
    mail($reciever, $subject, $msg, $headers);
}

David's comment provides the best advice:

If you abstract your mail dependency behind a custom object then internally that object can perform any pre- and post- tasks needed where it wraps the call to mail()

However, if you choose not to follow that route, you can rename and replace the mail() function

rename_function('mail', 'new_mail');
override_function('mail', '$string', 'return override_mail($string);');

function override_mail($string){
    return new_mail($string);  
}

See further information and comments here: http://www.php.net/manual/en/function.override-function.php . Note that rename_function and override_function are intended for debugging use, and are provided by the Advanced PVP Debugger package.

Have a look at APD override_function.