Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Repeatable email fields to be used in the TO and Mail Headers for notifications #11

Open
briandesp opened this issue Aug 11, 2018 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@briandesp
Copy link

No description provided.

@briandesp briandesp changed the title Allow Repeatable email fields to be used in the TO and Mail Headers Allow Repeatable email fields to be used in the TO and Mail Headers for notifications Aug 11, 2018
@YuvrajKhavad
Copy link

Hello @felipeelia
Any update regarding this problem.

Thanks

@felipeelia felipeelia added the enhancement New feature or request label Oct 10, 2019
@chloemccarty
Copy link

chloemccarty commented Dec 9, 2019

I have an [email] field in my repeater and I needed to send a confirmation to each of those emails from Mail 2. If you have a similar situation, you can add the following code to your functions.php file
Be sure to review the comments to update the code where necessary.

// make sure plugin is active on site
if ( is_plugin_active( 'cf7-repeatable-fields/cf7-repeatable-fields.php' ) ) {
	
	/* Allows multiple email fields from the repeatable email field in form #78223 in Mail 2
	*/
	function fx_wpcf7_repeatable_recipient($mail2, $form) {
		// BE SURE TO UPDATE BELOW WITH YOUR OWN FORM ID
		if ( $form->id != 78223 ) return $mail2;
		$to = array();
		// I added some JS to prevent the user from adding more than 4 emails, but you can add more if you need
		if( isset( $_POST['email__1'] ) )
			$to[] = $_POST['email__1'];
		if( isset( $_POST['email__2'] ) )
			$to[] = $_POST['email__2'];
		if( isset( $_POST['email__3'] ) )
			$to[] = $_POST['email__3'];
		if( isset( $_POST['email__4'] ) )
			$to[] = $_POST['email__4'];

		$to = implode( ',', $to);
		$mail2['mail_2']['recipient'] = $to;
		
		return $mail2;
	}
	add_action( 'wpcf7_additional_mail', 'fx_wpcf7_repeatable_recipient', 99, 2);
}

@felipeelia
Copy link
Owner

Thanks for sharing your solution @chloemccarty !

@keeslina
Copy link

This is great! @chloemccarty can you share the JS to prevent the user from adding more than X number of repeater fields as well?

@HristinaJ
Copy link

Recently I had a similar scenario as @chloemccarty, where I need to send emails through Mail to multiple recipients. Also, I use repeatable [emails] field. Following the provided solution for Mail 2 and after modifying code to fit on the Mail form, I added the following code in the functions.php.

// make sure plugin is active on site
if ( is_plugin_active( 'cf7-repeatable-fields/cf7-repeatable-fields.php' ) ) {	
	// define the wpcf7_mail_components callback 
	function filter_wpcf7_mail_components( $components, $form, $instance ) { 
		// make filter magic happen here... 
                // BE SURE TO UPDATE BELOW WITH YOUR OWN FORM ID
		if ( $form->id != [FormID]) return $components;
		$to = array();		
		$i = 1;
		while( isset( $_POST['friend-email__'.$i] ) ) {
    		        if( isset( $_POST['friend-email__'.$i] ) ) {
				$to[] = $_POST['friend-email__'.$i];
				$i++;
			}
		}
		$to = implode(',', $to);
		$components['recipient'] = $to;
		return $components; 
	}; 

	// add the filter 
	add_filter( 'wpcf7_mail_components', 'filter_wpcf7_mail_components', 10, 3 ); 
}

@n-mitchell
Copy link

@HristinaJ @chloemccarty Any idea how to get this working in the additional headers (Bcc) rather than just the To field?

@HristinaJ
Copy link

HristinaJ commented Jun 4, 2020

@n-mitchell I think it can be achieved using $components['additional-headers'] instead of $components['recipient'], but haven't tested it.

$components['additional_headers'] = "Bcc: $bcclist";

@n-mitchell
Copy link

n-mitchell commented Jun 5, 2020

@HristinaJ Thanks, got it working with this:

$components['additional_headers'] = "Bcc: $bcclist";

@felipeelia felipeelia added this to the 2.1.0 milestone Jul 23, 2023
@cscupcake
Copy link

Are these solutions mentioned above still applicable to the latest version?
How are we able to send an email confirmation to repeated emails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants