public
Created

Google Docs Survey Emailer

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
function onFormSubmit(e) {
var to_email = "YOUREMAIL@YOURCOMPANY.COM";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var spreadsheet_name = ss.getName();
var sheet = ss.getSheets()[0];
var columns = sheet.getRange("A1:U1").getValues()[0];
 
var email_subject = "New response for [" + spreadsheet_name + "]";
var email_body = "Spreadsheet: " + spreadsheet_name + "\r\n\r\n";
var email_body_html = "<p><b>Spreadsheet: " + spreadsheet_name + "</b></p>";
for (var i = 0; i < columns.length; i++) {
var question = columns[i];
if (question != "") {
var answer = e.values[i];
email_body = email_body + question + "\r\n" + answer + "\r\n\r\n";
email_body_html = email_body_html + "<p><b>" + question + "</b><br/>" + answer + "</p>";
}
}
 
var optAdvancedArgs = {replyTo: to_email, htmlBody: email_body_html};
MailApp.sendEmail(to_email, email_subject, email_body, optAdvancedArgs);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.