How to use ‘phpmailer_init’ SMTP settings only on certain ‘wp_mail’ actions?
phpmailer_init will always fire for every wp_mail() call – however, you can hook/unhook it conditionally like so: function wpse_224496_phpmailer_init( $phpmailer ) { // SMTP setup // Always remove self at the end remove_action( ‘phpmailer_init’, __function__ ); } function wpse_224496_wp_mail( $mail ) { // Example: only SMTP for emails addressed to [email protected] if ( $mail[‘to’] === … Read more