Created
January 4, 2014 22:31
-
-
Save adiroiban/8261604 to your computer and use it in GitHub Desktop.
Example for sending confirmation email for Google Forms. You still need to manually configure the trigger and attach it to onFormSubmit.
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
// Code under Public Domain. | |
function onFormSubmit(event) { | |
// event.responses - FormResponse | |
var response = event.response.getItemResponses(); | |
// Update 5 with yout email field. | |
var recipient = response[5].getResponse(); | |
// Update 0 with your name field. | |
var name = response[0].getResponse(); | |
// Email address only of owner of the form. | |
var owner = 'MYEMAIL@gmail.com'; | |
// Content of main confirmation. | |
var content = [ | |
'Hi,', | |
'', | |
'We have received your form!', | |
'', | |
'Regards,', | |
'My name' | |
].join('\n'); | |
var subject = 'Confirmation form submission for ' + name; | |
var from = 'My NAME'; | |
if (!recipient) { | |
subject = 'Submission without email ' + name; | |
MailApp.sendEmail(owner, subject, '', {name: from}); | |
return | |
} | |
try { | |
MailApp.sendEmail(recipient, subject, content, {name: from}); | |
// We send another copy so that it will reach our inbox, not only Sent emails. | |
MailApp.sendEmail(owner, subject, content, {name: from}); | |
} catch(error) { | |
var subject = 'Submission with errors for ' + name; | |
MailApp.sendEmail(owner, subject, error.message, {name: from}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment