PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Send notification to more than one email

  1. I am 2 email fields in my form, one is the person you wish to send the information to, the other is the sender (both being dynamic user entered values), ...i want to send a copy of the generated email to both parties however the notification to user only accepts one dynamic field and the notification to admin does not accept a dynamic field.

    I tried inserting the field variable {Email Address:4} in the BCC field of the user notification, but no luck, ...anyone got a solution (sorry could not find in the forums or help).

    Thanks,

    Posted 13 years ago on Wednesday July 21, 2010 | Permalink
  2. You will need to use a hook to accomplish what you need. Try the following code snippet. You will need to replace the form Id and the field Ids to match your values.
    Let me know if you have any questions.

    add_filter("gform_autoresponder_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
    
        //applying notification routing to form Id 2
        if($form["id"] != 2)
            return $email;
    
        //creating email list from fields 2 and 3.
        return $_POST["input_2"] . "," . $_POST["input_3"];
    }
    Posted 13 years ago on Thursday July 22, 2010 | Permalink
  3. Hi,

    I am trying this solution out but can not get it to work, probably because I have placed the code in the wrong block of the themes functions.php file?

    Based on the solution your provided, I have altered the vairables so that it applies to my form id 12. I have also changed the field id's accordingly. Are there anyother vairables I need to alter and where exactly do I place this code in functions.php file?

    add_filter("gform_autoresponder_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
    
        //applying notification routing to form Id 12
        if($form["id"] != 12)
            return $email;
    
        //creating email list from fields 14 and 22.
        return $_POST["input_2"] . "," . $_POST["input_3"];
    }

    Kind Regards,

    David

    Posted 13 years ago on Friday November 19, 2010 | Permalink
  4. David,
    The location in functions.php doesn't matter. It should work anywhere in that file.
    I did notice that in your code above your field IDs are still the same as mine. That might be the issue.
    Try replacing

    //creating email list from fields 14 and 22.
    return $_POST["input_2"] . "," . $_POST["input_3"];

    With

    //creating email list from fields 14 and 22.
    return $_POST["input_14"] . "," . $_POST["input_22"];
    Posted 13 years ago on Friday November 19, 2010 | Permalink
  5. I build a website in which each post represent a small company with its contact information and each one have a custom field named "email". I want to display the form on the category template and after the submission the notification to be sent to all emails of the posts of that specific category.
    Is there any hook for this?
    Thanx

    Posted 13 years ago on Sunday November 28, 2010 | Permalink
  6. Yes, there is a hook to set the TO address for the Admin Notification. It accepts multiple email addresses separated by commas. The hook is:

    gform_notification_email

    Example usage:

    <?php
    add_filter("gform_notification_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
    return "test@test.com";
    }
    ?>

    The User Notification also has it's own hook for setting the TO address. That hook is:

    gform_autoresponder_email

    Posted 13 years ago on Monday November 29, 2010 | Permalink
  7. This hook is great, but it breaks when there are multiple fields and some of them are empty. So if I have 5 email fields that are filled in by the user, I want all 5 of those emails addresses to get the autoresponder. But if the user on fills in 3 of the 5 it all breaks down and none get sent. So I did a switch/case and tried to check for empty results like this:

    //GForm autoresponder hook
    add_filter("gform_autoresponder_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
    	$value = "";
    	switch ($value) {
    		case ($_POST["input_33"] != "") :
    		$value .= $_POST["input_33"] . ",";
    		break;
    		case ($_POST["input_39"] != "") :
    		$value .= $_POST["input_39"] . ",";
    		break;
    		case ($_POST["input_42"] != "") :
    		$value .= $_POST["input_42"] . ",";
    		break;
    		case ($_POST["input_52"] != "") :
    		$value .= $_POST["input_52"] . ",";
    		break;
    		case ($_POST["input_58"] != "") :
    		$value .= $_POST["input_58"];
    		break;
    		default :
    		$value = $email;
    		break;
    	}
    	return $value;
    }

    But it's still not working. Are there any suggestions you can make so that a user doesn't have to fill in all 5 email fields and it will still send to the ones they did fill in?

    Thanks in advance, love the plugin!

    Posted 13 years ago on Tuesday February 22, 2011 | Permalink
  8. Your code probably isn't appending the values, it's most likely only hitting the first switch and doing that one because the switch only runs once. It's not running every field through that switch statement because there is no loop. An if statement would probably be better in this situation. Do an if statement instead of a switch, with an if statement for each field and if it's value isn't blank then append the value.

    Posted 13 years ago on Tuesday February 22, 2011 | Permalink
  9. Thanks Carl. This works:

    //GForm autoresponder hook
    add_filter("gform_autoresponder_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form) {
    	$a = $_POST["input_33"];
    	$b = $_POST["input_39"];
    	$c = $_POST["input_45"];
    	$d = $_POST["input_52"];
    	$e = $_POST["input_58"];
    
    	$value1 = $a;
    	$value2 = $a . "," . $b;
    	$value3 = $a . "," . $b . "," . $c;
    	$value4 = $a . "," . $b . "," .$c . "," . $d;
    	$value5 = $a . "," . $b . "," .$c . "," . $d . "," . $e;
    
    	if (($a != "") && ($b != "") && ($c != "") && ($d != "") && ($e != "")) {
    	return $value5;
    	} elseif (($a != "") && ($b != "") && ($c != "") && ($d != "")) {
    	return $value4;
    	} elseif (($a != "") && ($b != "") && ($c != "")) {
    	return $value3;
    	} elseif (($a != "") && ($b != "")) {
    	return $value2;
    	} elseif ($a != "") {
    	return $value1;
    	} else {
    	return $email;
    	}
    }

    But realized it was completely irrelevant because I had the wrong ID in one of the {Email:ID} fields...which by the way, will kill anything following that field. So if in the BCC: field you had {Email:1},{Email:2},{Email:3} and ID_2 was incorrect for some reason, then ID_3 wouldn't be sent to. Just an FYI. Thanks guys.

    Posted 13 years ago on Tuesday February 22, 2011 | Permalink

This topic has been resolved and has been closed to new replies.