Skip Navigation

[Resolved] Toolset Form notification to multiple WP users

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 3 voices.

Last updated by umbertoZ 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1332471

Hi, I need to send a Toolset Form notification to multiple WP users.

Is it possible to pass a list of IDs separated by comma by a Generic field if I select "Send notification to a WordPress user with an ID coming from a generic field in the form"?

Or, is there another option to send the notification to multiple WP users?

thanks

#1332695

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi there,

Thank you for contacting us and I'd be happy to assist.

By default, the "Send notification to a WordPress user with an ID coming from a generic field in the form" option can be used to send email to only a single WordPress user.

To make it work with multiple WP user IDs, you'll need a custom function, hooked to "cred_notification_recipients" hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

Example:


add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {

	// Check notification name matches target notification
	if ( ( isset($notification['name']) && 'admin notification name' == $notification['name'] ) && ($form_id == 12345) ) {

		if ( !empty($_POST['user_ids']) ) {
			$user_arr = explode(',', $_POST['user_ids']);

			foreach ($user_arr as $users) {

				$user_obj = get_userdata(trim($users));

				$user_email = $user_obj->user_email;
				$user_display_name = $user_obj->display_name;

				$recipients[] = array(
					'to'        =>  'to',
					'address'   =>  $user_email,
					'name'      =>  $user_display_name,
					'lastname'  =>  ''
				);

			}
		}

	}
	
	return $recipients;
}

The above code can be added into the active theme's "functions.php" file and please replace "admin notification name" with the actual name of your notification and '12345' with the actual ID of your form.

Next, in your notification, you can create a hidden generic field with field slug "user_ids" and then select that field in the "Notification e-mail recipients" settings.

I hope this helps and please let me know if you need any further assistance around this.

Note: For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1334289

Hey, thanks a lot, the code works perfect. Just a question. How can I chage it to send emails bcc?

I tryed changing:

'to' => 'to',

to:

'to' => 'bcc',

but it doesn't work for me.

Any suggestion?

thanks

#1335295

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Waqar has a couple of days holiday, so let me jump in here.

I'm guessing that there needs to be at least one "to" even if the rest are all "bcc" (because according to the documentation what you've done should work).

Does $recipients already contain a "to" entry?

You could update the notification settings to also send the email to a specific email address so that there is at least one "to".

#1335389

My issue is resolved now.

I've just to set an email on " Send notification to a specific email address: " field (I used a not existing email like wordpress@my-domain.com) and now it works fine.

I've also set "Send notification to a WordPress user with an ID coming from a generic field in the form:" to bcc and changed the custom code to 'to' => 'bcc'.

Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.