Skip to content

Instantly share code, notes, and snippets.

@snipe
Last active November 16, 2017 21:37
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save snipe/5416863 to your computer and use it in GitHub Desktop.
Save snipe/5416863 to your computer and use it in GitHub Desktop.
Script to get the contents of a Google form submission emailed to you.
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "you@example.com";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "New Hire: ";
// 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)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[2]].toString() + " - starts " + e.namedValues[headers[15]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
// Based off of a script originally posted by Amit Agarwal - www.labnol.org
// Credit to Henrique Abreu for fixing the sort order
}
@oemb1905
Copy link

  1. How can I change it to draw the email from a column and row in the form instead of entering a static email?
  2. I'm getting errors on line 15 when I run the script. Am I doing something wrong?
  3. Do I need to change lines 7 and 15 to reflect what data I want to pull? If so, do you have a completed version as an example to draw from?
  4. You mention in the script notes in line 19 that you are drawing from the 3rd and 16th columns. Where is this specified in the code?

@gituncar
Copy link

gituncar commented Apr 7, 2016

Hi, if possible add new value (random number) on last column and sent on email confirmation this value, when person filled out form
Column 17 or last

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment