FROMDEV

How-To Send Auto Reply Email on Google Form Submission

google form automatic email
Google forms is one of the most popular contact form on the web and a lot of people are not aware that you can also send automatic reply to the submitter of form messages using some Google API code.

Google form auto reply email is not a in built feature, however we can achieve it by simple script. There is a simple way to Send the contact form in the form of email to your inbox described here. However, if you want a automated reply email sent to your customers it needs to be done using some JavaScript function which can be easily configured to be called inside Google forms.

Google form automatic email can be easily triggered on the form submission.

Below are the steps to configure a automated response email for your Google form.

Why Send Auto Reply

The default Google contact form feature provides a google docs spreadsheet with user responses, and responding to them needs to be done using manual emails. Sometimes its not feasible to reply back to people immediately, I have found some of the main reasons as listed below

  • In case your site is really popular and lot of people are trying to reach you.
  • There may be lot of spam contact messages.
  • There may be worldwide customers trying to reach you during odd working hours/weekends.
  • You may be on vacation.
  • You need some time to do research before you respond.
  • Some of the categories need not be attended since your answers can be canned. e.g. you want to thank your customer for providing feedback or some help.

Below are simple steps to setup the auto reply email.

  1. Create Contact Form
  2. In case you have not created the contact form before, don’t worry. Its really easy and free. Checkout this simple Youtube Video about “How To Create Contact Form on Google Docs“. This example assumes you have at least four fields in your contact form (Name, Email, Subject and content/message). Checkout our contact form for details.

  3. Add JavaScript Function for Auto Reply Email
  4. Below is the JavaScript code which can be used to send automated email reply. This code uses Google MailApp utility to send reply. Follow these steps and copy the below code Tools – Script Editor – Copy Below code into the text editor. – Save.

    function sendAutoReply(e) {
    
        // Remember to replace abc@youmail.com with your own email address
        // This will be used to send you a email notification in case of error on form
        // for example if someone entered a wrong email address.
    
        var myemail = Session.getActiveUser().getEmail();
    
        //Leave this field blank - it will be auto populated from "Email" field in 
        // your contact form. Make sure you have a "Email" Field in your contact form.
        var email = "";
    
        // This is going to be the subject of reply email
        // You can change it as per your requirements
    
        var subject = "Re: ";
    
        // The variable e holds all the form values in an array.
        // Loop through the array and append values to the body.
    
        var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. nn-----nn";
        var columns, mysheet;
    
        try {
            mysheet = SpreadsheetApp.getActiveSheet();
            columns = mysheet.getRange(1, 1, 1, mysheet.getLastColumn()).getValues()[0];
            if (e) {
                // This is the submitter's email address
                var em = e.namedValues["Email"];
                if(em) {
                  email = em.toString();
                } else {
                  throw {'message':'Email Field is required. Please add a field called Email in your sheet.'}
                }
                var sub = e.namedValues["Subject"];
                if(sub) {
                  subject += sub.toString();
                }
                // Only include form values that are not blank
                for (var keys in columns) {
                    var key = columns[keys];
                    if (e.namedValues[key]) {
                        message += key + ' :: ' + e.namedValues[key] + "nn";
                    }
                }
    
                // We are using JavaScript MailApp util of Google Apps Script
                // that sends the email.
    
                MailApp.sendEmail(email, subject, message, {
                    replyTo: myemail
                });
            } else {
                var err = 'Required Input params are passed only during live form submission. Please try the script by submitting the live form.';
                Logger.log(err);
                throw {
                    'message': err
                };
            }
    
        } catch (e) {
            MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message + ' nncolumns: ' + columns + ' nnmessage: ' + message);
        }
    }
    
    

    Special Caution

    Please make sure you take care of following things when you create a form and update any code in script.

  • Google forms auto response will be sent immediately with email content configured in your script. Make sure to update the email response “message” in the script before you start using this.
  • Field names are case sensitive. Please make sure the field names are exactly matching in the script. (e.g. Email, Subject)
  • Make sure to update the script with your own email address on this line

    var myemail = “abc@youmail.com”;

  • In case you want the auto reply content to be really big make sure you split it into multiple lines (and use Javasctipt append) like below instead of keeping all text in one double quote.

    var message = “Thanks for contacting FromDev.com. We will get in touch with you shortly. nn—–nn”
    + “Another line n”
    + “Another line”;

  • Add a Trigger
  • The next steps is to add a trigger to run the script on form submission. The trigger is a simple configuration to tell google docs to listen to specific event and take action on it. We are simply going to create a trigger at the event of form submission and execute our auto reply email script in the action response to that event. Follow these steps

    • Tools – Script Editor – Resources – Current Script’s Triggers
    • Select Function name “sendAutoReply”
    • Select “From Spreadsheet”
    • Select “On Form Submit”
    • Save

  • Authorize Script
  • You need to Authorize Script to be run by Google API. The authorization step is really important since Google API will not run the script unless its authorized by the creator. Therefore make sure you are creating the script using the same account which owns the contact form.

  • Lets Test our Script
  • I believe in test driven development, and as always try to make sure your setup is working fine. This is really simple, just do the form submission using a email address and see if the auto reply email is received as required.

  • Something went wrong?
  • Your script is still not working? There can be following reasons – Please make sure you have the exact same field names in your contact form. (Specially for Email and Subject). Checkout our contact form. – If someone enters a invalid email address or other error happens on your form, you would be notified with a email similar to below snapshot.

    March 2014: Updated: Changes in Google Drive affected new forms.
    March 2013: Updated: Error Handling and Reply to Option as per reader feedback.

    Hope you found this tutorial useful. Which contact form application are you using?

    Exit mobile version