Created
July 18, 2012 01:30
-
-
Save brendannee/3133467 to your computer and use it in GitHub Desktop.
Google Forms Confirmation Email
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
function formSubmissionResponseEmail(event) { | |
var form = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = form.getActiveSheet(); | |
var formName = form.getName(); | |
var timestamp = event.values[20]; | |
var admin = "[email protected]"; // reply-to and errors email address | |
var emailContent = "Thank you. We have received your request for free $10 BART tickets. Your tickets will be sent to the mailing address you provided via U.S. Postal Service within four business days. For Questions call Corinne at 925-969-1193. This BART ticket offer is funded by the Contra Costa Transportation Authority's Half Cent Sales Tax For Transportation Improvements (Measure J) and the Bay Area Air Quality Management District's Transportation Fund for Clear Air."; | |
var recipient = event.values[20]; | |
// No admin email - nothing you can do. Stop | |
if (admin == null || admin == '') return; | |
//No recipient email | |
if (recipient == null || recipient == '') return; | |
try | |
{ | |
var parameters = event.namedValues; | |
for (var column in parameters) | |
{ | |
if(parameters.hasOwnProperty(column)) | |
{ | |
var patt=new RegExp('\\['+column+'\\]','g'); | |
var temp = emailContent.replace(patt,parameters[column]); | |
emailContent = temp; | |
} | |
} | |
} catch (e) { | |
MailApp.sendEmail(admin, "Error replacing fields for form", e.message + " " + formName + " at " + timestamp); | |
return; | |
} | |
try { | |
//var advancedArgs = {htmlBody:bodyHTML1+bodyHTML2+bodyHTML3 , replyTo:email}; | |
var advancedArgs = {replyTo:admin}; | |
body = emailContent; | |
MailApp.sendEmail(recipient, "Your Response Was Received on " + formName, body, advancedArgs); | |
} catch(e){ | |
MailApp.sendEmail(admin, "Error sending response for form", e.message + " " + formName + " at " + timestamp ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment