Skip to content

Instantly share code, notes, and snippets.

@tmsss
Last active June 7, 2017 13:23
Show Gist options
  • Save tmsss/288b34753ac448c42f30e7806a11156d to your computer and use it in GitHub Desktop.
Save tmsss/288b34753ac448c42f30e7806a11156d to your computer and use it in GitHub Desktop.
Send E-mail uppon submission of Google Form (insert script in the form's spreadsheet)
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "email@domain.##";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var htmlBody = '';
var name = e.namedValues[headers[1]].toString();
var replyTo = e.namedValues[headers[2]].toString();
var subject = "E-mail subject";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
for(var i in headers)
htmlBody += '<h3>' + headers[i] + '</h3>' + '<p>' + e.namedValues[headers[i]].toString() + '</p>';
// Send the email
MailApp.sendEmail({
to: email,
name: name,
replyTo: replyTo,
subject: subject,
htmlBody: htmlBody,
});
// Based off of a script originally posted by Amit Agarwal - www.labnol.org
// Credit to Henrique Abreu for fixing the sort order
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment