8
votes

How do I send a notification email after a form has been submitted?

I have a Google Form, I open it and I go to menu More->Script Editor and add a script:

function OnSubmit(e) {
  MailApp.sendEmail ("[email protected]", "Form Submited: Foo feedback " + Date.now(), "Form Submited: Foo feedback");
}

I save the script and test it works by pressing the run button. The email gets delivered to [email protected].

Then I fill in the Google Form, but the email does not arrive in [email protected] mailbox.

P.S. I do not want to use "Email Notifications for Forms" plugin because it requests access to to many privileges. I do not want to use "Form Notifications" because for some reason it does not work for me (the emails do not get delivered).

3
Kindly try manually creating a "On form submit" trigger and attaching it to your function. Let me know if this work. - Umair Mohammad

3 Answers

5
votes

Finally found it, well hidden under

  • Edit form mode
  • Responses tab
  • ... menu button
  • Get email notifications for new responses.

enter image description here

4
votes

To send an email on submit you need to save this script, test it in the script editor (and accept when you see the permissions popup), and then submit a form.

The script looks for submit triggers, if it finds none it adds a new one that sends the email.

function respondToFormSubmit() {
   MailApp.sendEmail ("[email protected]", "Form Submited: Foo feedback " + Date.now(), "Form Submited: Foo feedback");
}

var form = FormApp.getActiveForm();
var triggers = ScriptApp.getUserTriggers(form);

var existingTrigger = null;
for (var i = 0; i < triggers.length; i++) {
  if (triggers[i].getEventType() == ScriptApp.EventType.ON_FORM_SUBMIT) {
    existingTrigger = triggers[i];
    break;
  }
}
if (!existingTrigger) {
  var form = FormApp.getActiveForm();
  var trigger = ScriptApp.newTrigger('respondToFormSubmit')
  .forForm(form)
  .onFormSubmit()
  .create();
}
0
votes

enter image description here

The easier way, now, is to use the "Notification rules..." item under "Tools".

enter image description here