How to add confirmation emails to google forms

Have you ever used google forms to get some input from your users? It is really easy to set up a google form, add the required input fields and share the form with your users. Here’s an example of a google form.

After the users fill in the form, they will see a short confirmation message on the screen and their responses will be stored. You might also want your users to get a confirmation email after filling out the form. This is not the default behavior of google forms though so you will have to add a small script to do so.

If you fill in and submit the example form you will receive such a confirmation email and see what we are going to set up.

Here’s what you have to do:

  • from the form edit screen choose the tools menu option
  • pick script manager and click the new button
  • you will be redirected to a new page for adding the script
  • pick form in the popup
  • add a name for your script file
  • clear the code if there is any example code in there
  • add the following code:

The code is pretty straightforward: it received the user response as a parameter, it gets an array with the individual answers for each question (itemResponses), it gets the response for each question, sets the subject and the body of the email to be sent and sends the email to the user.

There’s is only one more step to go, we need to set a trigger for this function:

  • go to resources from the menu
  • pick current projects triggers
  • you will notice there are no triggers set up. click on click here to add one now
  • you need to select the method to run (onFormSubmit) and the trigger event from form and on form submit
  • you can also set the notification options – the default is to receive a daily email with the errors that come up, but for testing purposes you could set it to send error messages immediately
  • click save and authorize the app as requested

And that’s it! you now have the needed script. You need to go back to the forms edit page, from the scripts manager popup you need to refresh the scripts list and pick the newly added onFormSubmit script.

And you’re done! You’re ready to test out your form and send it out to your users!

Let me know if you have any questions! ๐Ÿ™‚

16 thoughts on “How to add confirmation emails to google forms

  1. Hi! Thanks for this. I get the error message: TypeError: Cannot read properly “response” from undefined. What does that mean?

    • Hey ๐Ÿ™‚ When are you getting this error? Double check that the trigger for this method was set up properly as described ๐Ÿ˜‰

  2. I set up everything as you said (i think). I did it again now, and I get the same error message. I pops up when I try to a run the onFormSubmit script from the script manager.

  3. Hi, I am trying out this code as well, but is met with the following error. Read through these threads, but still can’t seem to fix it.

    I need help!

    function onFormSubmit(e) {
    var response = e.response;
    var itemResponses = response.getItemResponses();
    var timestamp = itemResponses[0].getResponse();

    This is the error I get

    TypeError: Cannot call method “getItemResponses” of undefined. (line 3, file “Code”)

    I believe it has something to do with this line
    var itemResponses = response.getItemResponses();

    What is wrong? ๐Ÿ™

    • Hey!

      Please double check that you set the correct trigger for this action ๐Ÿ™‚ There might be something wrong set there.

      Also, how did you test this? Did you fill in the form or did you run it from the script managed? It’s easier to test by filling in the form and submitting it.

  4. Hi Aniri,

    I tested it by filling in the form and submitting it.

    Current project’s triggers as such

    Run onFormSubmit – Events “from spreadsheet, on form submit”

    That’s correct right?

    • Hey

      I think the problem might be the fact that you are using a spreadsheet instead of a form. Can you check with a form?

      I have the following:
      Run onFormSubmit โ€“ Events โ€œfrom form, on form submitโ€ –

  5. Hi there, thanks very much for a great little script. This is the first time I’ve ever done anything with a Google script though, so am having a little trouble debugging this problem:

    The script successfully sends e-mails, but only if all fields were filled out. e.g. let’s say that field 2 was optional. That means the hard-coded indices for the fields after that no longer correspond to their expected contents. e.g. if the e-mail address should have been itemResponses[3], if the second item wasn’t entered, then the e-mail address is now itemResponses[2]. This means that the script gets the wrong values, and can end up trying to send to invalid e-mail addresses and not correctly populating the body of the message. And you can get an out-of-bounds problem when trying to access the last value(s).

    Any hints on how to deal with this? I’m surprised it happens, as I assumed that blank entries would get null values, rather than changing the number of response values in the array.

    • Hey Michael!

      That’s an interesting issue! I’ve never ran into it though since I only used forms with mandatory questions.

      But I guess you could go through the array and check which answer corresponds to which question. The ItemResponse class also has a method getItem() that can be used to retrieve the data about the question the answer belongs to. You can check the documentation here:

      I hope this helps!

      • Hi Irina, thanks so much for your considered reply and the link to the correct documentation: I wouldn’t have known where to start otherwise.


  6. I suggest ‘Form Confirmation Emails’ add-on (developed based on Form Notifications code) as the other solution for confirmation and notification emails. It supports Html formatting for email’s content. So, you can setup the professional email with the banner, link, and any submission’s answers as you want. You can choose send or not based on respondent’s multi-choices and select list answers. The add-on also let you and your form’s collaborator set up the sending configurations separately.

    • Hi!

      Yes, what you suggest should be possible ๐Ÿ™‚ What exactly is not working in the example you provided?

  7. Thanks for the tips and brief tutorial , quite helpful in getting the help regarding the addition of confirmation mail to google forms.

Leave a Reply

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