-
-
Save WProbot/5aeb8705a15b79f58c640adae7aa9c03 to your computer and use it in GitHub Desktop.
wp_mail() add bcc based on contents of subject line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php // DO NOT include this line. Add below to your theme functions.php | |
| /** | |
| * Add bcc address to email based on contents | |
| * of the email subject line. | |
| * | |
| * Set email address and content of the subject | |
| * line for the email being filtered. | |
| */ | |
| add_filter( 'wp_mail', 'custom_mails' ); | |
| function custom_mails( $args ) { | |
| // What email to bcc? | |
| $bcc_email = sanitize_email( 'example@email.com' ); | |
| // Welcome email subject line (or specific static portion of the subject line). | |
| $welcome_email_subj = "Welcome email subject"; | |
| if ( strpos( $args['subject'], $welcome_email_subj ) ) { | |
| if ( is_array( $args['headers'] ) ) { | |
| $args['headers'][] = 'Bcc: ' . $bcc_email; | |
| } else { | |
| $args['headers'] .= 'Bcc: ' . $bcc_email . "\r\n"; | |
| } | |
| } | |
| return $args; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment