Last active
December 31, 2024 17:02
-
-
Save New0/27f30c83fcce84b77e645cdb26c3e98b to your computer and use it in GitHub Desktop.
Intercept Ninja Forms email to remove the BCC option from email headers and send theme separately.
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 | |
/* | |
Plugin Name: Ninja Forms Custom email send | |
Description: Testing Ninja Forms email hook to catch bcc and send them separately | |
Version: 1.0.0 | |
*/ | |
add_filter( 'ninja_forms_action_email_send', 'nf_custom_email_send', 10, 5 ); | |
function nf_custom_email_send( $return, $action_settings, $message, $headers, $attachments ) { | |
//Intercept precise email action, EDIT 21 to the precise action ID | |
if( $action_settings['id'] === 21 ) { | |
$recipients = [$action_settings['to']]; | |
foreach( $headers as $key => $header_line ) { | |
if( strpos( $header_line, 'Bcc:' ) === 0 ) { | |
$bccs = explode( ',', $action_settings['bcc'] ); | |
foreach( $bccs as $bcc ) { | |
$recipients[] = $bcc; | |
} | |
unset($headers[$key]); | |
} | |
} | |
foreach( $recipients as $recipient ) { | |
$sent = wp_mail($recipient, strip_tags($action_settings['email_subject']), $message, $headers, $attachments); | |
if (!$sent) { | |
$return = false; | |
break; | |
} | |
} | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment