Created
February 12, 2016 09:46
-
-
Save inutano/80ffb231fef3db4c171b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks Amit! http://www.labnol.org/internet/auto-confirmation-emails/28386/ | |
/* Send Confirmation Email with Google Forms */ | |
function Initialize() { | |
var triggers = ScriptApp.getProjectTriggers(); | |
for (var i in triggers) { | |
ScriptApp.deleteTrigger(triggers[i]); | |
} | |
ScriptApp.newTrigger("SendConfirmationMail") | |
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()) | |
.onFormSubmit() | |
.create(); | |
} | |
function SendConfirmationMail(e) { | |
try { | |
var ss, cc, sendername, subject, columns; | |
var message, value, textbody, sender; | |
// This is your email address and you will be in the CC | |
cc = "[email protected]"; | |
// This will show up as the sender's name | |
sendername = "Your Name Goes Here"; | |
// Optional but change the following variable | |
// to have a custom subject for Google Docs emails | |
subject = "Google Form Successfully Submitted"; | |
// This is the body of the auto-reply | |
message = "We have received your details.<br>Thanks!<br><br>"; | |
ss = SpreadsheetApp.getActiveSheet(); | |
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0]; | |
// This is the submitter's email address | |
// Make sure you havea field called Email Address in the Google Form | |
sender = e.namedValues["Email Address"].toString(); | |
// Only include form values that are not blank | |
for (var keys in columns) { | |
var key = columns[keys]; | |
var val = e.namedValues[key] ? e.namedValues[key].toString() : ""; | |
if (val !== "") { | |
message += key + ' :: ' + val + "<br />"; | |
} | |
} | |
textbody = message.replace("<br>", "\n"); | |
GmailApp.sendEmail(sender, subject, textbody, { | |
cc: cc, | |
name: sendername, | |
htmlBody: message | |
}); | |
} catch (e) { | |
Logger.log(e.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment