...
function SendConfirmationMail(e) { // e is an event object that is defined by the event of form submission. Contains submission info.
var ss, bcc, sendername, subject, headers, ptest;
var message, value, textbody, sendto;
bcc = "ensemble-tickets@mit.edu";
sendername = "MIT Shakespeare Ensemble";
subject = "EXAMPLE Ticket Reservation Confirmation";
message = "We have received your ticket reservation.<br>Thank you!<br>Please arrive to pick up your reservation at least 15 minutes before performance time.<br>The performance will be in La Sala de Puerto Rico (W20-202), on the second floor of the MIT Stratton Student Center at 84 Massachusetts Ave.<br><br>";
ss = SpreadsheetApp.getActiveSheet();
headers = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0]; // Creates an array of the column headers.
ptest = ss.getRange(ss.getLastRow(), 1, 1, ss.getLastColumn()).getValues()[0]; // Gets the last row from the spreadsheet. Will be used instead of e.
Logger.log(headers); // Adds headers to log. Note that the log is not actually used for anything :P
Logger.log(ptest);
// Logger.log(e); // Adds event object in its entirety to the log.
// sendto = e.namedValues['Email Address'][0]; // Pulls the email address from the event object.
sendto = ptest[headers.indexOf('Email Address:')] // Pulls the email address by finding the index within headers. Make sure the name of the header here exactly matches what it is on the form or it won't work!
for (var i in headers) { // For every key in headers
// value = e.namedValues[headers[i]][0].toString(); // Gets the value corresponding to a specific header from the event object. Makes it a string. This line is hard for a human to read.
value = ptest[i].toString() // Gets the value corresponding to a specific header.
Logger.log(value); // Adds this value (such as "Peter" for "First Name") to the log.
if ((i !== "0") && (value !== "")) { // If this is not the Timestamp && the form field was not left blank.
message += headers[i] + ' :: ' + value + "<br>"; // Add the header, a little space, the form input value, and then a line break.
}
}
textbody = message.replace("<br>", "\n"); // This changes the HTML line break character to the text interpreter line space character.
GmailApp.sendEmail(sendto, subject, textbody, // Sends an email to the person who filled out the form, with a previously defined subject and body.
{bcc: bcc, name: sendername, htmlBody: message, replyTo: bcc}); // This is an optional field. Adds bcc to us and changes the name of the sender. htmlBody makes it so that devices capable of rendering HTML will render that instead. replyTo sets the default reply-to address, us.
}
...