Skip to content

Instantly share code, notes, and snippets.

@adiroiban
Created January 4, 2014 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiroiban/8261604 to your computer and use it in GitHub Desktop.
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.
// 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