Sending Confirmation Emails with a Google Docs Form

Posted on Jun 18, 2011 in Tech Tips & Tricks | 275 comments

Screenshot of a Google Apps Script

I love Google Apps. Gmail, Google Docs, Google Voice–all brilliant, indispensable products in my opinion.  Being able to create forms in Google Docs for quick polls and surveys is also very handy, but the extremely limited feature set has been frustrating to me. One surprising lack is that of being able to send a confirmation email to the user. Granted, not all forms necessarily even have a field for the user to enter their email.

[Original post 6/18/11. Edited 10/29/11 to add HTML email to the example. Edited 4/21/12 to add more screenshots and correct “Triggers menu” to “Resources menu”.]

With a quick script, you can rectify this and customize an email that will be sent to the user. Don’t be intimidated by the code–if you can handle writing raw HTML, you will be able to modify this script to suit your needs.

However, if you’ve never used a Google Form before, you probably want to play around with that and get comfortable with that first. The rest of this assumes that you have created a form and are viewing the attached spreadsheet.

Update: make SURE you are looking at the spreadsheet, as shown in the screenshot below. If you are viewing the form, you are in the wrong place. The script needs to be attached to the spreadsheet. Thanks to t1dude for pointing this out!

Screenshot - how to open the Script Editor in Google Docs
The first step, in Google Docs, is to click on “Tools” and then “Script Editor.” A new window will open, with an empty function called “myFunction.” Overwrite the contents of this window with the code you want to use. Below I’ve added a complete example that you can rework to your needs.

function onFormSubmit(e) {
var timestamp = e.values[0];
var yourName = e.values[1];
var toAddress = e.values[2];
var eventName = e.values[3];
var visitDate = e.values[4];
var visitComments = e.values[5];
var subject = "CAP Confirmation - " + eventName + " " + visitDate;
var emailBody = "Thank you for your Club Ambassador Program report submitted on " + timestamp +
"\n\nThe details you entered were as follows: " +
"\nYour Name: " + yourName +
"\nYour Email: " + toAddress +
"\nClub or Event Name: " + eventName +
"\nVisit Date: " + visitDate +
"\nVisit Comments: " + visitComments;
var htmlBody = "Thank you for your <b>Club Ambassador Program</b> report submitted on <i>" + timestamp +
"</i><br/>&nbsp;<br/>The details you entered were as follows: " +
"<br/><font color=\"red\">Your Name:</font> " + yourName +
"<br/>Your Email: " + toAddress;
var optAdvancedArgs = {name: "Club Ambassador Program", htmlBody: htmlBody};
MailApp.sendEmail(toAddress, subject,
emailBody, optAdvancedArgs);

Screenshot - Script Editor after pasting sample script
See the first section, with “e.values”? Those refer to the form fields. “e.values[0]” will always be the timestamp. “e.values[1]” will be the first field in your form, and so on.

Feel free to change the variable names. If the first form field isn’t the respondent’s name, but is actually their favorite color instead, you can certainly change it from yourName to faveColor. Just make sure to change all occurrences of the identifier.

If you have fewer form fields, remove the lines you don’t need. If you have more, copy and paste the existing lines, making sure to increment the numbers… so “e.values[27]” would be the 27th form field, and so on. You do not need to reference every form field in your script–just have lines for the ones you want to include in the email.

Next, we put together some strings (a string of words) to be put into the email. If the text is in quotation marks, it will appear just like you entered it. If the text is not in quotation marks, then it refers to one of the variables we just set up. Plus signs concatenate those strings, and every line needs to end in a semicolon.

“\n” is special. In quotation marks, this refers to a newline character… a line break. Add that whenever you would press “enter” in the email if you were writing it by hand.

Modify the “subject” line as necessary. Yours might be simpler or more complex.

Modify the body section as necessary. This was broken up into multiple lines just for readability. It could all be on one line. Just make sure to have plus signs to connects different strings of text, and only to have one semicolon (at the end).

The “optAdvancedArgs” section is special. It refers to special settings (anything beyond the basic to, subject and body settings) for an email. You don’t have to use it. You can simply remove that, changing that line to:

MailApp.sendEmail(toAddress, subject,

Want to set other advanced arguments, like a cc line, an HTML body for the email and more? View the MailApp Script Reference and scroll to the bottom of the page for a list of what you can set and examples of how to use them.

A few notes on HTML emails:

  • If you provide an HTML version of the email, also provide plain text for those email clients that can’t see the HTML version.
  • Emails don’t work like web pages. Writing HTML for an email is like making a website in the 90’s. Read the linked article or do some Googling to find out what tags you should and shouldn’t use.
  • Email clients tend to be narrow. Don’t count on having much horizontal space.
  • When you are writing a Google Docs script and need to refer to a quote character, such as when writing attributes in an HTML tag, use a backslash before the single or double quote, or else Google Docs will think you’re ending the string. Check the example for when a font color is added to “your name”

Modify the script, and then save it. However, there is one more important step to take to get this to work!
Screenshot - Triggers Menu
In the script editing window (not the normal Google Docs window), click on the “Resources” menu. Click “Current Script’s Triggers…” and then “Add a new trigger.”
The first field should be “onFormSubmit,” the second “From Spreadsheet” and the third “On form submit.” Change these if necessary and add the trigger. You will need to give your approval for Google to allow the form to send emails.

If you do not set the trigger, the script will never run. The trigger is necessary to run the code whenever a form is submitted.

There! Now try submitting a form and make sure the email looks the way you want.


  1. Hi there, I found your website by means of Google whilst looking for a comparable subject, your web
    site got here up, it seems to be good. I have bookmarked it in my google bookmarks.

    Hello there, just turned into aware of your blog thru Google, and located that
    it is really informative. I am gonna watch out for
    brussels. I will be grateful in the event you proceed this in future.

    Lots of folks will be benefited from your writing.

  2. First of all I would like to say awesome blog!
    I had a quick question in which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear your head prior to writing.
    I’ve had a tough time clearing my mind in getting my thoughts out there.
    I do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally wasted simply just trying to
    figure out how to begin. Any recommendations or hints?

  3. Those who rrun good quality anti-viruses onn their
    computers will more than likely not have as
    much problem with viruses and should look to another source for
    their slow computer. As great as the Android tablets are, there is one thing that
    they ‘ like other tablets ‘ are missing. Sometimes a virus might just corrupt data
    and files so they’re irreparable, and sometimes they might just muddy the waters
    off your computer to slow it down and become frustrating and irritating for its operator (aka you).
    Wired Equivalent Privacy was introduced in
    1997 and is the original version of wireless network security.
    Or, should you be anything lijke me, you won’t ever took the
    time to memorize your Blac – Bery PIN, so you’re forced tto visit Options after which Status on your Black – Berry menu anyy time you
    must hunt for the answer.

  4. This is in fact the reality! That’s precisely whats occurring in todays society.

    Many thanks for letting us understand.

  5. I don’t even know how I ended up here, but I thought this post was great.

    I don’t know who you are but certainy you are going to a famous blogger if you are not already ;) Cheers!

  6. Remarkable! Its genuinely remarkable article, I have got
    much clear idea concerning from this paragraph.

  7. Quality posts is the important to be a focus for the viewers to
    go to see the website, that’s what this site is providing.

  8. The design is also purely sterilized to provide optimum safety to the patients lying over its surface.
    Unlike surgery that is invasive and involves several risks, the chiropractic treatment for Lumbar disc herniation benefits from its drug-free and natural methods of providing healthcare.

    when the spinal injury occurs from accidents, falls, tension, over-exertion, the inability of the spine to compensate can result in changes
    in movement or position of the vertebrae.

  9. I am extremely inspired together with your writing abilities and also
    with the format in your weblog. Is this a paid subject matter
    or did you customize it your self? Either way stay up the excellent quality writing, it’s uncommon to see a great weblog like this
    one these days..

  10. Hello, I would like to subscribe for this blog to get hottest updates, thus where can i do it please

  11. It is prudent to read the contract documents.

    Framing, walls, number of doors that’ll be mandatory, no matter
    what you need and do it without going broke. This hut was created during World War II, industrial metal buildings have several benefits
    when compared against the more traditional wooden buildings.

    If you want a standing seam roof or the screw down roofing panel is the most crucial part of your decision.
    It takes less time in the construction of Pre-engineered steel buildings are much decrease
    maintenance and will provide you with a structure without breaking any laws.

  12. Can I simply say what a comfort to discover someone who genuinely knows what they are talking about
    over the internet. You certainly know how to bring a problem to light and
    make it important. More and more people need to check this out and understand this side of
    the story. I was surprised that you’re not more popular because you most
    certainly possess the gift.

  13. You actually reported that well!

  14. For some people at some times, it is precisely this different sort of relationship
    that is needed for the conversation to happen. Natália Rita stays with the CPPD (UK) Counselling School
    where she is taking the Advanced Diploma in Humanistic Integrative Counselling.
    But for many other people, there are times when this may not be

  15. Wow, amazing blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your web site is magnificent, as well as
    the content!

  16. What’s up, this weekend is good in support of me,
    as this occasion i am reading this enormous educational post here at
    my residence.

  17. This is really interesting, You’re a very skilled blogger.
    I have joined your rss feed and look forward to seeking more of your magnificent
    post. Also, I have shared yolur ebsite in my social networks!

  18. It’s an amazing piece of writing for all the internet people; they will obtain advantage from it I am sure.

  19. Hello this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if
    you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

  20. Well, I think their tutorial is much more detailed than mime.

    During his journey, the boy learns about the language of the world,
    omens and pursuing his Personal Legend. Even surviving life right now seems all-important we can’t avoid thinking about different versions of “the Afterlife.

  21. And always make sure it’s 100% organic (some companies load their
    superfood up with Niacin and other non-organic components — go for the organic green superfood and avoid
    the Niacin hangover). Part of the confusion about superfoods comes from the fact that they are often backed up by some
    legitimate scientific research; however, the conclusions may be blown
    way out of proportion, becoming dubious claims eagerly accepted
    as fact. You need to have a number of superfoods in your diet daily.

  22. Hello
    Thanks for the tutorial
    You say ““e.values[1]” will be the first field in your form, and so on.”
    Actually, e.values[1] is the first non-blank field of the form. Which can cause problem if some fields remain unfilled. Is there a way to fix this ?

  23. Hello,

    The instruction seems straightforward enough, but when troubleshooting the script I get the following error message: “TypeError: Unable to read the property “values” from undefined. (Line 2, file: Code)”.

    What does this mean and how can this error be fixed?

  24. Emma–make sure that you are testing the script by setting up the trigger and submitting the form, so the form row data (“e”) is passed to the function. Do not run it directly from the code view; it will have no input, no “e” to use.

  25. You can certainly lotopyeer see your skills in the work you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. At all times follow your heart.


  1. Forms confirmation | Info007cleanin - [...] Sending Confirmation Emails with a Google Docs Form | AlamoxieJun 18, 2011 … One surprising lack is that of …
  2. Project 2, Day 1 – Codecademy and Javascript | An Hour Each Day - [...] no quick and easy way to do this in Google Docs forms, but there’s a great little tutorial here …
  3. Using Google docs to send email « News Apps Blog - [...] I thought it was a pretty cool solution and sounds like something that would be helpful to other folks, …
  4. Send Confirmation Emails upon submission of Google Form…. » Open School Sites - [...] [...]
  5. Google app script – how to count number of google form response | - [...] copied code from a tutorial. But need help to get the count of form responses. Here is how it …
  6. Beware of Secret Clauses in On-line Vehicle Auctions | 99th Level Gaming - - [...] you have any questions about wherever and how to use seized car auctions michigan, you can call us at …

Submit a Comment

Current ye@r *

Manage your comment subscriptions