I have a wordpress site that have plugins: Contact form 7, WP Mail SMTP Plugin by Mail Bank, Spartpost...All of these plugins are able to send out email by anyway (wp_mail, smtp, http api)...

I am developing another plugin that will do my custom action on each sent out email by any plugin.

Currently, I can do the custom action on contact form 7 email with:

add_action('wpcf7_before_send_mail', 'my_custom_action', 10, 1);

My question: is there any hook, filter or something that is general to wordpress email? Instead of use action/filter of every plugins?

Thank you.

1 Answer 1


Every WordPress email usually uses wp_mail(). Which is actually a wrapper of PHPMailer. Find out this wp_mail() functions documentation and source code, you'll find some hooks there which will be useful to you cases.

But keep it in mind that, those hooks will be applicable only if the mail is sent by using wp_mail(). If any email is send by any other function like the PHP native mail() function then the hooks may not work.

  • Hi @the_dramatist, Thanks for your answer. Actually, I already add: add_filter('wp_mail','my_custom_action', 10,1); But it no use. At least, I run test mail of SMTP Plugin by Mail Bank but my custom action not get executed.
    – Rain
    Commented Dec 8, 2017 at 4:05
  • As I said, if the plugin isn't using wp_mail() function then the hooks will not work. So, have look in to the plugin's source code and see what function of method they are using to send the e-mail. This way you'll get an overview on why it's not working.
    – CodeMascot
    Commented Dec 8, 2017 at 4:24
  • Thank the_dramatis, the plugin actually use another way to send mail.
    – Rain
    Commented Dec 13, 2017 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.