How to send an email on form submission

How to send an email on form submission

To send an email using Google Apps Script upon Google Form submission, you can use a form submission trigger. A form submission trigger is a special type of Apps Script trigger that runs when a user submits a response to a Google Form.

To set up a form submission trigger, follow these steps:

  1. Open the Script Editor: In Google Forms, go to the “Responses” tab and click the “Script Editor” button. This will open the Script Editor in a new tab.
  2. Create the trigger: In the Script Editor, go to the “Edit” menu and select “Current project’s triggers”. In the “Add trigger” dialog, set the following options:
  • Choose which function to run: Select the function that you want to run when the form is submitted.
  • Select event source: Choose “From form”.
  • Select event type: Choose “On form submit”.
  1. Write the email function: In the Script Editor, write a function that sends an email. You can use the GmailApp.sendEmail() function to send the email. For example:
function sendEmail(e) {
  // Get the form response
  var formResponse = e.response;

  // Get the email address from the form response
  var email = formResponse.getResponseForItem().getResponse();

  // Set the email subject and body
  var subject = "Your email subject";
  var body = "Your email body";

  // Send the email
  GmailApp.sendEmail(email, subject, body);

This function will get the email address from the form response and use it to send an email with the specified subject and body.

  1. Test the trigger: Submit a response to the form to test the trigger. If everything is set up correctly, the script will send an email immediately.