How to send multiple notification emails separately and manually with custom content? [RESOLVED]

A though question. My form sends emails to users based on check boxes which are checked. The emails are sent as BCC. I need to customize content of each email based on the user it is sent to.

How do i do this? As all these notification emails are sent all at once via the BCC header. I need to split them up and send them individually I guess. But how?

You can have as many email notifications as you like. Go to the notifications page for your form, and click the “Add New” button up top to add a new notification. Then configure that to go to whoever you want and with whatever message you want. There’s additional information here about configuring notifications:

Hi Chris, thanks for your reply. Maybe I didn’t explained it clearly enough. As I get how that works, it is super basic GF stuff. I have implemented highly customized form handling already.

So let me try to explain differently. The form has 1 notification set. In this example it is sent to 10 out of 100 available receivers (via selected checkboxes updated by ajax). These 10 email copies of the same notification are sent by BCC (as I do not want people to see who else receives the notification).

Now the problem: the BCC emails are sent at all once by the BCC header ($email[‘headers’][‘Bcc’]) so they are all the same. I’d like to ‘intercept’ the notification emails (just) before they are sent so I can personalize the content of each one of them. Maybe by using something simple as str_replace(‘FIRSTNAME’, ‘$firstname’, $email[‘message’]) or something. But this would affect all messages so they would all have the same first name. So to be able to customize them all I think I need to send them 1 by 1? Correct?

So maybe I’m just looking for a way to send the notification emails manually and above all separately.

Which function does the sending of the notification, and in which hook do i place the sending code? gform_pre_send_email ?

Hope this explains! Thanks!

Got it, thanks for the explanation. I recommend using gform_notification:

Thanks for the reply Chris. How would i use the gform_notification hook to modify (personalise) each BCC email notification before it is sent?

Editing the $notification['message'] would in my opinion edit all the bcc emails at once to the same values (the last of the loop). Which would not make it possible to send each recipient an email with their own first name for example.

I don’t know if there is a way to modify the message for each person who is getting a BCC of a single notification, using any filter. gform_notification is the better filter for this purpose, but maybe that is not enough.

What sort of change do you need to make to each message, based on the email address it’s being sent to?

I believe my question is similar to his. What I would essentially like to do is create many notifications from one single notification.

Here is the whole purpose and plan:

  1. Someone fills out a Gravity Form that is a Report (ID: 5)

  2. The Filter catches (I think I am supposed to use the gform_notification hook

  3. The Filter uses a field, called mutual_id, from the Report to get_entries() from a separate form that contain the same mutual_id

  4. The Filter loops through the entries and extracts e-mail addresses

  5. The Filter creates e-mail notifications based on the original Notification for each of these e-mail addresses

    add_filter( 'gform_notification', 'notify_adopters' , 10, 3 );
    function notify_adopters ( $notification, $form, $entry ) {
     $mutual_id = $entry["32"];
     // Get all relevant adopters
     $other_form_id = 13;
     $search_criteria['field_filters'][] = array( 'key' => '1', 'value' => $mutual_id );
     $paging = array( 'offset' => 0, 'page_size' => 1000 );
     $send_to_these = GFAPI::get_entries( $other_form_id, $search_criteria, null,  $paging);
     // Get all of their e-mail addresses
     $to_emails[] = [''];
     foreach($send_to_these as $send_to_this) {
     	$to_emails[] = rgar( $send_to_this, 2 );
     // Now Create the e-mail notifications based on the to_emails
     return $notification;


1 Like

@chrishajer, I saw you liked my post but did not reply, and I realized that I didn’t ask an actual question. The following is what I was trying to ask:

Is there a way to create multiple separate notifications inside of this filter, which is triggered upon form submission?

I want to be sure that the template from the single notification is used, but that it is used to distribute to a large group of e-mail addresses that must be pulled from the entries of a separate gravity form.

Hi John. Sorry I missed the question. The gform_notification filter is going to send only one email.

It sounds like the submission of this form is the trigger to send to everyone who submitted your other form (the one where you are pulling the email addresses from the entries.) Rather than using gform_notification filter, you could use gform_after_submission as the time to notify all those adopter emails from your other entries. To send notifications in your code, you can use the GFAPI function send_notifications:

You can loop through all the addresses you have retrieved, using gform_after_submission, and call the send_notifications function in the loop once for each address. One other benefit of this is that the form submission will already be done, and the after submission code will run separately in the background without delaying the submission.

Let me know if you have any other questions about that.

Excellent, thank you!

The main reason I was attempting to use the Gravity Notification System was so that the long-term maintainers of the system can easily modify the e-mail templates, but I could also do that with a Custom Post Type, just was trying to keep it contextual.

For now I’ve gone the route of a single gform_notification with the BCC field being populated, but I will probably implement your solution in the future. Thanks again!

Thanks John. I’m glad you found something that works.

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.