• Resolved thankssforhelp

    (@thankssforhelp)


    Hi there,

    I hope you are doing well.

    I have a further question concerning recipients. I am using the following php code to enter recipients in the recipients field – using the shortcode {multiple-mails}:

    <?php
    add_filter( 'forminator_form_get_admin_email_recipients', 'wpmudev_set_multiple_mail_recipients', 10, 5 );
    function wpmudev_set_multiple_mail_recipients( $email, $notification, $prepared_data, $module, $entry ) {
    	if( $prepared_data['form_id'] != 8489 ){
    		return $email;
    	}
    
    	if( $notification['recipients'] == '{multiple-mails}' ) {
    		$my_post = get_post(8644);
    		$mails = str_replace( '"', '', str_replace( ']', '', str_replace( '[' , '', $my_post->post_content)));
    		$mails = array_filter( explode( ",", $mails ), function($value) {
    			return ( $value !== NULL && $value !== FALSE && $value !=='' );
    		});
    		if( $mails ){
    			$email = $mails;
    		}
    	}
    
    	return $email;
    }

    This all works perfectly fine. However, I would like the recipients to receive the emails in bcc, so that they cannot see all other recipients. Therefore I added {multiple-mails} in the section advanced > BCC Emails but couldn’t get any results.

    I know I am doing something wrong here and would be greatful if you could help me (again) with your great support.

    Kind regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @thankssforhelp

    I hope you’re well today!

    The BCC addresses is a different configuration option in notification settings and it needs to be changed via a different filter hook.

    This code should help:

    add_filter( 'forminator_custom_form_mail_admin_bcc_addresses', 'wpmudev_set_bcc_multiple_mail_recipients', 10, 2 );
    function wpmudev_set_bcc_multiple_mail_recipients( $bcc_mails, $custom_form ) {
    	
    	error_log( print_r( $custom_form, true ) );
    	
    	if ( '8489' !== $custom_form->id ) {
    		return $bcc_mails;
    	}
    	
    	if ( $bcc_mails == '{multiple-mails}' {
    		
    		$my_post = get_post(8644);
    		$mails = str_replace( '"', '', str_replace( ']', '', str_replace( '[' , '', $my_post->post_content)));
    		$mails = array_filter( explode( ",", $mails ), function($value) {
    			return ( $value !== NULL && $value !== FALSE && $value !=='' );
    		});
    		if( $mails ){
    			$bcc_mails = $mails;
    		}
    		
    	}
    	
    	
    	return $bcc_mails;
    	
    	
    }

    Best regards,
    Adam

    Thread Starter thankssforhelp

    (@thankssforhelp)

    Hi Adam,

    thank you for the quick reply.

    I tried the above php snippet, however when I refresh the website an error occurs:

    Parse error: syntax error, unexpected ‘;’ in …. on line 13″

    and another question: where would I have to add further form-id’s when using the snippet for several forms?

    Thanks a lot in advance and kind regards

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @thankssforhelp

    Thanks for response and sorry for the error – that’s my oversight.

    First, please remove this line as it’s not needed (it was just me checking something):

    error_log( print_r( $custom_form, true ) );

    Second, to fix the parse error, replace this line

    if ( $bcc_mails == '{multiple-mails}' {

    with this

    if ( $bcc_mails == '{multiple-mails}' ) {

    Finally, to use for multiple forms you just need to change this

    if ( '8489' !== $custom_form->id ) {

    with this

    $my_forms = array( '8498', '123', '567' ); // put forms IDs here
    if ( ! in_array( $custom_form->id, $my_forms ) ) {

    Best regards,
    Adam

    Thread Starter thankssforhelp

    (@thankssforhelp)

    Hi Adam @wpmudev-support8,

    thank you for your response. Following the above instructions I got the following code:

    <?php
    add_filter( 'forminator_custom_form_mail_admin_bcc_addresses', 'wpmudev_set_bcc_multiple_mail_recipients', 10, 2 );
    function wpmudev_set_bcc_multiple_mail_recipients( $bcc_mails, $custom_form ) {
    	
    	$my_forms = array( '8489', '9393' ); // put forms IDs here
    if ( ! in_array( $custom_form->id, $my_forms ) ) {
    		return $bcc_mails;
    	}
    	
    	if ( $bcc_mails == '{multiple-mails}' ) {
    		
    		$my_post = get_post(8644);
    		$mails = str_replace( '"', '', str_replace( ']', '', str_replace( '[' , '', $my_post->post_content)));
    		$mails = array_filter( explode( ",", $mails ), function($value) {
    			return ( $value !== NULL && $value !== FALSE && $value !=='' );
    		});
    		if( $mails ){
    			$bcc_mails = $mails;
    		}
    		
    	}
    	
    	
    	return $bcc_mails;
    	
    	
    }

    Unfortunately, this code somehow does not work. No email is sent when the form is filled out and submitted.

    With the code I sent at the beginning everything works, only the mails are not sent as BCC, but “normally.”

    Possibly I am doing something wrong here. I have tried and tested it many times during the day, but have not come to any result.

    Kind regards

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @thankssforhelp

    You’re right. I tested the code in general but using only error_log entries as testing tool and apparently that was not enough.

    It requires another slight modification, mostly because apparently the BCC e-mails are additionally filtered in plugin code (and there’s no way around it) so using the “multiple-mails” placeholder in BCC address field in notification is not correctly validated and doesn’t trigger e-mails.

    The solution is to modify it a bit. The code would be as follows:

    add_filter( 'forminator_custom_form_mail_admin_bcc_addresses', 'wpmudev_set_bcc_multiple_mail_recipients', 10, 2 );
    function wpmudev_set_bcc_multiple_mail_recipients( $bcc_mails, $custom_form ) {
    	
    	$my_forms = array( '8489', '9393' ); // put forms IDs here
    	if ( ! in_array( $custom_form->id, $my_forms ) ) {
    		
    		return $bcc_mails;
    	}
    	
    	if ( in_array( '[email protected]', $bcc_mails ) ) {
    	
    			
    		$my_post = get_post(8644);
    		$mails = str_replace( '"', '', str_replace( ']', '', str_replace( '[' , '', $my_post->post_content)));
    		$mails = array_filter( explode( ",", $mails ), function($value) {
    			return ( $value !== NULL && $value !== FALSE && $value !=='' );
    		});
    		
    				
    		if( $mails ) {
    			$bcc_mails = $mails;
    		}
    		
    		
    	}
    	
    	
    	return $bcc_mails;
    	
    	
    }

    and in your notification settings in “Advanced” section in “BCC Emails” field put this fake e-mail address instead

    [email protected]

    I’ve tested it again – this time fully, really testing form submissions with additional BCC addresses, and it worked fine.

    Note: I did put e-mails manually in my code during testing and I’m assuming that the part that reads e-mails from your post works fine anyway (and creates an array with e-mails).

    This modification is not required for your original code that you used before – that one worked and will work the same. It’s only the version for BCC addresses.

    Best regards,
    Adam

    Thread Starter thankssforhelp

    (@thankssforhelp)

    Hi Adam @wpmudev-support8,

    so many thanks, it now works smoothly and perfectly – this was an important step for me.

    I hope that many others will also learn to appreciate the value of your work. ??

    Kind regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Recipients in BCC’ is closed to new replies.