How to Send Email Based on Response in Google Forms

How to Send Email Based on Response in Google Forms

Google Forms allows you to collect your respondents’ answers and opinions in a number of ways, whether it’s a simple quiz or a long quiz. While it has several handy native features, Google Forms does not yet allow you to send email notifications to yourself or the respondent natively.


How to send an email based on the response in Google Forms

The latter comes to the photo if you want to thank the user for their response and their time. On the other hand, if your form is aimed at a large audience and involves multiple departments, sifting through all the responses to the form takes time.

Fortunately, there are a few workarounds whereby you can send emails to the owner or individuals. Now there are two ways to go ahead with this.

You can either send an email based on your form response. Or, you can send one based on the responses users chose. And as stated earlier, both methods require the help of an external add-on. And since you’ll be sending an email from your account, you’ll need to provide the appropriate permissions to the add-on or feature.

Now that this is all set, let’s get started, shall we?

How to send a generic email using Google Forms

Sending a generic email to the user or owner is luckily not rocket science. The aptly named Form Notifications add-on allows you to send simple thank you emails to users.

Step 1: Once the form is created, click on the three-dot menu on the right and select Add-ons from the list. This will take you to Google Marketplace.

How to send email based on response in Google Forms 2


How to send email based on response in Google Forms 2

2nd step: Now find Form Notifications and click on it to install it.

Then create the form. If you want to send the emails directly to the respondent, select the Collect emails check box under Settings.

How to send email based on response in Google Forms 3


How to send email based on response in Google Forms 3

Or, you can define a form question asking for the user’s email and mark it as required as shown below.

How to send email based on response in Google Forms 4


How to send email based on response in Google Forms 4

Step 3: Once done, click on the little add-on icon and select Form Notifications. You will see a prompt in the lower right corner.

How to send email based on response in Google Forms 5


How to send email based on response in Google Forms 5

Activate the button for the thank you email.

How to send email based on response in Google Forms 6


How to send email based on response in Google Forms 6

As mentioned previously, you can use the Automatically field or the Form field. Select the one that best suits your needs. At the same time, you can also add a Bcc for the email by filling in the “Send a copy to” field.

Step 4: Then add the subject and body of the email, and that’s it! Save the settings and click the Preview icon at the top to see if the current configurations work for you.

How to send email based on response in Google Forms 7


How to send email based on response in Google Forms 7

This is a straightforward add-on and its setup is straightforward and straightforward. And the Posted by Google Cloud tag also makes it a bit unreliable.

Apart from the above, you can also email yourself (or the creator) when the form reaches a fixed number of responses.

To do this, activate the “Notify on the response of the form” button. The creator’s email will be automatically filled in in the recipient field. It’s not hard-coded and you can enter other email addresses as well.

How to send email based on response in Google Forms 1


How to send email based on response in Google Forms 1

Once done, add the notification threshold and hit the save button. Now your form will send an email as soon as it crosses the response threshold.

How to send responses based on responses

Let’s put it there. If you want to send responses based on your form responses, it’s not easy like the process above. Here you will have to tinker with the connected spreadsheet application script.

Fortunately, if you have a simple form, it should be easy to do. In our case, we have a simple form where we ask respondents for their preferred vacation spot.

2 How to send email based on response in Google Forms 89


2 How to send email based on response in Google Forms 89

And based on the responses they provide on the form, an email will be triggered to a defined email address. Of course, the code can be changed according to the requirements of your form.

Step 1: Once your form is created, click on the Responses tab and tap the little spreadsheet icon on the right. This will connect your form to a spreadsheet.

2 How to send email based on response in Google Forms 3


2 How to send email based on response in Google Forms 3

2nd step: Go to the spreadsheet and click Tools> Script Editor.

2 How to send email based on response in Google Forms 4


2 How to send email based on response in Google Forms 4

In the script editor, paste the following lines of code,

function checkLocation(e) {
 var subject="";
 var values = e.namedValues;
 var prefLocation="";

for (Key in values) {
 var label = Key;
 var data = values[Key];
 prefLocation=data;
 Logger.log(data);
 }
}

Here e is the event that will be triggered when submitting the form, while the e.namedValues The object will bring you the form data in the form of an array.

Once this data is captured, the For statement will iterate through the array to bring you the data. Ultimately, the form data for that particular response will be attributed to the prefLocation variable.

Step 3: Meanwhile, click on the little clock icon on the left panel to access Triggers and select Add Triggers.

2 How to send email based on response in Google Forms 6


2 How to send email based on response in Google Forms 6

Here, select From spreadsheet as the event source and On form submission as the event type.

2 How to send email based on response in Google Forms 7


2 How to send email based on response in Google Forms 7

The above will ensure that the function we wrote above will only be triggered when the form is submitted. And when submitting, it will only extract the data from the connected worksheet.

Step 4: Now go back to the script editor to modify the code as needed.

In our case, we want an email sent to a particular email id when a respondent replies to Hills, and so on.

So we added a simple If and Else-If condition to the code,

 function checkLocation(e) {
 var subject="";
 var values = e.namedValues;
 var prefLocation="";

 for (Key in values) {
 var label = Key;
 var data = values[Key];
 prefLocation=data;
 Logger.log(data);
 if (prefLocation=="Hills"){
 subject="You have an email for Hills Location"; 
 GmailApp.sendEmail('abc@.gmail.com', subject, prefLocation);
 }else if (prefLocation=="Beaches"){
 subject="You have an email for Beaches Location";
 GmailApp.sendEmail('xyz@gmail.com', subject, prefLocation);
 } 
 else if(prefLocation=="Cities") {
 subject="You have an email for Cities Location";
 GmailApp.sendEmail('ghy@gmail.com', subject, prefLocation);
 }
}
}

Of course, you will need to provide authorization for the GmailApp.sendEmaiI work to work. It’s a one-time process though.

Step 5: Now that everything is in place, save your code by clicking on the Save icon as shown below.

2 How to send an email based on the response in Google Forms 29


2 How to send an email based on the response in Google Forms 29

Now run the code. Unfortunately, if there is no event, you will not be able to run code directly from the Script Editor.

To make your code work, submit your form. If everything is in the right place, there’s a good chance you’ll receive an email.

Once done, you can modify the code as needed and add individual If-Else conditions. At the same time, you can also compose the body of the email according to the data.

How to check for errors

Running error-free code the first time is rare, and to be fair, there are a lot of things that can go wrong. To check for errors, go to the Executions tab and you will see all the instances where the function was called.

2 How to send email based on response in Google Forms 9


2 How to send email based on response in Google Forms 9

Click to see the errors. Here you can also see how the function was called. A Trigger tag results in a form submission, while an Editor tag means the function was executed through the editor.

At the same time, if you want to cross-check the value of the function, just add the Logger.log (variable) to log the data.

2 How to send email based on response in Google Forms 2


2 How to send email based on response in Google Forms 2

For example, we had invoked Logger.log (prefLocation) in the individual If-Else conditions, and our log looked like the one above.

Also on Guiding Tech

To code or not to code

The second method may seem a bit complicated. But once you figure out what the individual functions are called, chances are things will get a little easier.

But ultimately, if you don’t want to get your hands dirty, you can check out the Email Notification Forms add-on. This is designed to send emails based on conditional responses. However, the conditional formatting feature is not free and costs around $ 4 per month for a single user license.

So, if you need to send responses for your forms occasionally, you can paste the above code into the App Script editor.

Last updated on June 4, 2021

The above article may contain affiliate links that help support Guiding Tech. However, this does not affect our editorial integrity. The content remains impartial and authentic.

(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src=”http://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=1652915528311925″;fjs.parentNode.insertBefore(js,fjs);}(document,’script’,’facebook-jssdk’));

See also  Best Carbon Footprint Calculator tools to calculate your Carbon Footprint

Leave a Reply

Your email address will not be published. Required fields are marked *