Get Google Forms Data in an Email
Google Forms can send email notifications as soon as people submit your online form but the actual form data isn’t included in the email message. You’ll have to open the associated Google Spreadsheet that is collecting the form responses to see the submitted data which is not always a very convenient option.
Here is script from Amit@labnol.org that you can use to achieve the same:
Here’s how you can add email notifications to any Google Form in few easy steps:
Create a new form in Google Drive or you can use any of your existing Google form. Inside the form editor, click “View Responses” to open the Google Spreadsheet that is collecting the responses of your Google Form.
While you are inside the spreadsheet, go to Tools –> Script Editor, remove any existing code and copy-paste the following snippet. Press Ctrl+S (or Cmd+S on Mac) to save the code and give your project any name (say “Send Google Forms by Email”).
Replace amit@labnol.org in line #40 with your own email address where the notifications will arrive. You can add multiple email addresses too separated by commas. You may also change the subject in line #43.
Go to the Run menu and choose Initialize. The Google Script will now require you to authorize the script – just click the Accept button and you’re done
/*
Send Google Form Data by Email v4.2
Written by Amit Agarwal amit@labnol.org
Source: http://labnol.org/?p=20884
*/
/**
* @OnlyCurrentDoc
*/
function Initialize() {
try {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers)
ScriptApp.deleteTrigger(triggers[i]);
ScriptApp.newTrigger("EmailGoogleFormData")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit().create();
} catch (error) {
throw new Error("Please add this code in the Google Spreadsheet");
}
}
function EmailGoogleFormData(e) {
if (!e) {
throw new Error("Please go the Run menu and choose Initialize");
}
try {
if (MailApp.getRemainingDailyQuota() > 0) {
// You may replace this with another email address
var email = "amit@labnol.org";
// Enter your subject for Google Form email notifications
var subject = "Google Form Submitted";
var key, entry,
message = "",
ss = SpreadsheetApp.getActiveSheet(),
cols = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
// Iterate through the Form Fields
for (var keys in cols) {
key = cols[keys];
entry = e.namedValues[key] ? e.namedValues[key].toString() : "";
// Only include form fields that are not blank
if ((entry !== "") && (entry.replace(/,/g, "") !== ""))
message += key + ' :: ' + entry + "\n\n";
}
MailApp.sendEmail(email, subject, message);
}
} catch (error) {
Logger.log(error.toString());
}
}
/* For support, contact developer at www.ctrlq.org */
Please make note that you need to paste the Google Script inside the Script Editor of the Responses Google spreadsheet and not the Google Form.
If you need to disable notifications, open the script editor again and choose Resources -> Current Script Triggers and delete the Form trigger associated with the “On Form Submit” action.
One more thing. Google Forms do not allow file uploads but you can use Google Scripts to allow anyone to upload files via a form to your Google Drive.