Answers / Question 5

Email the full answers of each Google Form response, not just a notification

Google Forms only tells you a response arrived. This short Apps Script emails every answer, with Reply going straight to the respondent.

The problem

You want each completed form to land in someone's inbox with all of its answers, so they can act on it without opening the response sheet. The built-in notification only says that a new response exists.

Inspired by a public question on Google Docs Editors Community. The problem above is described in our own words and the solution below is ours.

The fix

  1. Open the spreadsheet linked to the form (in the form: Responses → Link to Sheets).
  2. Extensions → Apps Script, paste the code, and set to.
  3. Run installFormTrigger once and approve. Every new submission now emails each question and answer.
Code.gsApps Script
// Email the full answers of every Google Form response (not just "you have a new response").
// Put this in the response spreadsheet: Extensions > Apps Script.
const FORM_MAIL = {
  to: '[email protected]',
  subject: 'New form response'
};

function formatAnswers(namedValues) {
  return Object.keys(namedValues)
    .filter(function (q) { return q !== 'Timestamp'; })
    .map(function (q) { return q + ': ' + [].concat(namedValues[q]).join(', '); })
    .join('\n');
}

function onFormSubmitHandler(e) {
  const nv = e.namedValues;
  const email = String((nv['Email Address'] || nv['Email'] || [''])[0]).trim();
  const options = {};
  if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) options.replyTo = email;   // Reply goes to the respondent
  MailApp.sendEmail(FORM_MAIL.to, FORM_MAIL.subject, formatAnswers(nv), options);
}

// Run once from the editor and approve the permissions.
function installFormTrigger() {
  ScriptApp.newTrigger('onFormSubmitHandler').forSpreadsheet(SpreadsheetApp.getActive()).onFormSubmit().create();
}

If the form collects an email address (a question named Email, or the built-in Email Address), pressing Reply on the notification writes straight back to the respondent.

Good to know

The script's logic is unit-tested against a simulated spreadsheet before publishing. Always try new automations on a copy of your sheet first.