Sunday, September 16, 2012

Digital Inspiration Technology Blog: Get Form Data from Google Docs in an Email Message [Video Tutorial]

Digital Inspiration Technology Blog
Digital Inspiration is an award-winning how-to tech blog around all things related to computer software, web applications, mobile and personal productivity.
Get Form Data from Google Docs in an Email Message [Video Tutorial]
Sep 11th 2012, 12:20

google docs email

Whether you are looking to add a basic "Contact Me" form to your website or need to create a complex online poll with conditional branching, Google Docs is an excellent tool for you. It offers a variety of themes, data can be easily exported and, unlike other polling software, your Google Docs forms can accept any number of responses without the fee.

There’s one limitation though. Google Docs can send email notifications as soon as people submit your online form but, as shown in the above screenshot, there’s no form data included in that email message. You’ll have to open the corresponding Google Docs spreadsheet to see that actual form data which is not always a very convenient option.

From Google Docs Form to your Email Inbox

Should you wish to receive Google Docs form data in an email message as soon as a user submits the form, there’s an easy workaround as explained in the following video.

The trick is that you associate a send mail routine with your Google Docs form that triggers as soon as a "form submit" action happens. And this routine, written using Google Apps Script, does all the magic – it reads the form values that were just submitted and sends them all in one message to a pre-defined address.

Here’s how you can add email capabilities to your Google Forms step by step:

    1. Create a new form in Google Docs (or use any of your existing forms) and switch to your Google Docs dashboard. Open the Spreadsheet associated with the Google Form.
    2. Go to Tools – > Script Editor and choose “Blank Project.” Remove any existing code in the code editor window and copy-paste the following code. Save the project.
    3. Replace “XYZ” in the code with your own email address where you want to receive the form email notifications.
function sendFormByEmail(e)   {        // Remember to replace XYZ with your own email address    var email = "XYZ";       // Optional but change the following variable    // to have a custom subject for Google Docs emails    var subject = "Google Docs Form Submitted";        // The variable e holds all the form values in an array.    // Loop through the array and append values to the body.      var s = SpreadsheetApp.getActiveSheet();    var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];        var message = "";          // Credit to Henrique Abreu for fixing the sort order      for(var i in headers)      message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";       // This is the MailApp service of Google Apps Script    // that sends the email. You can also use GmailApp here.      MailApp.sendEmail(email, subject, message);       // Watch the following video for details    // http://youtu.be/z6klwUxRwQI      // By Amit Agarwal - www.labnol.org  }
  1. From the Resources menu, choose Current Script’s Triggers and set up a new trigger. Replace "On Open" with "On Form Submit" and save the trigger.
  2. The script with require you to authorize Google Docs to access your Gmail account (for sending email). Just say yes and you’re done.

Advanced users can further customize the script to have custom email subject lines that match one of the form fields. Alternatively, you can specify the form submitter’s email address as the replyto address and thus you can directly respond to the user by replying to that email notification.

Also see: Perform Mail Merge in Gmail using Google Docs

Tweet this Share on Facebook


Digital Inspiration @labnolThis story, Get Form Data from Google Docs in an Email Message [Video Tutorial], was originally published at Digital Inspiration on 11/09/2012 under Google Docs, Polls, Internet.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions

No comments:

Post a Comment