From Google Docs Form to your Email Inbox

http://www.labnol.org/internet/google-docs-email-form/20884/

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:

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.
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.
Replace “XYZ” in the code with your own email address where you want to receive the form email notifications.


==========Copy code below making sure to Replace “XYZ” in the code with your own email address ======

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
}

 


====End of Code do not copy this line====

 

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.
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.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk