Do something after sending email. I did some digging into the PHPMailer
class and found that it supports a custom action.
Here’s how the callback is activated with the doCallback()
method in the class.
There’s also a PHPMailer
test on GitHub using this feature via the callbackAction()
callback.
Here’s an example how we can apply this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Custom PHPMailer action callback */ function wpse_mail_action( $is_sent, $to, $cc, $bcc, $subject, $body, $from ) { do_action( 'wpse_mail_action', $is_sent, $to, $cc, $bcc, $subject, $body, $from ); return $is_sent; // don't actually need this return! } /** * Setup a custom PHPMailer action callback */ add_action( 'phpmailer_init', function( $phpmailer ) { $phpmailer->action_function = 'wpse_mail_action'; } ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.