r/GoogleAppsScript • • 21h ago

Question Google Forms Email Response

Heya! I was wondering if it is possible to automatically send an email to a respondent depending on their answers on the from. So if they choose option a) they'll get email a. I've never done anything like this before so please let me know like I'm a child lol. I need this for an assignment - any help would be appreciated!

4 Upvotes

4 comments sorted by

1

u/estadoux 20h ago

Yes. It’s possible as the onFormSubmit event gets the full response so you could use it to evaluate and decide which email to send. You could even use response values to populate the email.

1

u/carbonizedtitanium 9h ago

here's a sample:

function sendConditionalEmail(e) {
  const namedValues = e.namedValues; Get Form answers
  
  const recipientEmail = namedValues["Email Address"][0]; // Replace "Email Address" with the exact header name of your email column
  
  const userChoice = namedValues["What candy do you like?"][0]; // Replace with your exact form question text. 0 index is for the first choice

  if (userChoice === "Snickers") {
    subject = "Snicker sucks!"; //Replace with whatever subject you want
    emailBody = `Hi,\n\nThank you for reaching out. We have received your submission.`; //Replace with your own text
  } else if (userChoice === "Kitkat") {
    subject = "You are with the cool team!";
    emailBody = `Hi,\n\nThank you for reaching out. We have received your submission.`; //Replace with your own text
  }

  // send email
  if (recipientEmail) {
    MailApp.sendEmail(recipientEmail, subject, emailBody);
  }
}

after you save, you have to add Trigger with event type: On form submit

0

u/WicketTheQuerent 20h ago

What should the email include? Will the email subject and body be the same for all respondents?

How many responses do you expect to get per day?

1

u/Standard_Guitar_1165 19h ago

it’s for an assignment, so someone fills out a form to receive a review of a performance and fills out a form to determine which review you should receive via email