Created
February 10, 2015 22:03
-
-
Save aniav/926f4667911ba1d138b8 to your computer and use it in GitHub Desktop.
Send Confirmation Email with Google Forms
This file contains 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
/* 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, sendername, subject, columns, from; | |
var message, value, textbody, sender; | |
// This is one of your identities in gmail | |
// you have to set the identity in gmail beforehand | |
from = '[email protected]'; | |
// This will show up as the sender's name | |
sendername = "Django Girls Your City"; | |
// Optional but change the following variable | |
// to have a custom subject for Google Docs emails | |
subject = "Thank you for filling out our form"; | |
// This is the body of the auto-reply | |
message = "We have received your details.<br>Thank you!<br> Below is a simple summary of your responses<br><br>"; | |
ss = SpreadsheetApp.getActiveSheet(); | |
columns = ss.getRange(1, 2, 1, ss.getLastColumn()).getValues()[0]; | |
// This is the submitter's email address | |
sender = e.namedValues["Your e-mail address:"].toString(); | |
// Only include form values that are not blank | |
for ( var keys in columns ) { | |
var key = columns[keys]; | |
if ( e.namedValues[key] ) { | |
message += key + ' : '+ e.namedValues[key] + "<br />"; | |
} | |
} | |
textbody = message.replace("<br>", "\n"); | |
GmailApp.sendEmail(sender, subject, textbody, | |
{from: from, 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