0

As you can see I am using this code to send an email to whoever submit the form. However, I do get the error that var emailTo = e.namedValues[2].toString(); has the error of

"TypeError: Cannot read property 'namedValues' of undefined (line 5, file "Code")"

function sendEmail(e) {

  var html = HtmlService.createTemplateFromFile("htmlemail.html")
  var htmlText = html.evaluate().getContent();
  var emailTo = e.namedValues[2].toString(); //column B is for the email

  var subject = "Thanks for participation";
  var textBody = "This email requires HTML support. Please make sure you open with a client that supports it."
  var options = { htmlBody : htmlText };

  if (emailTo!== undefined){
  GmailApp.sendEmail(emailTo, subject, textBody, options)
  }
}

Please help. Note that column B in the spread sheet is where the email should be filled.

Kowalski
  • 3
  • 2
  • e is undefined. How are you calling this function? – Pablo CG May 21 '20 at 14:17
  • Can you elaborate more? What should I do to make it work? – Kowalski May 21 '20 at 14:46
  • e is undefined because probably you're calling your `sendEmail` function incorrectly. – Pablo CG May 21 '20 at 15:16
  • Can you write an appropriate code to fix it ? – Kowalski May 21 '20 at 21:44
  • The required code depends on the object that you pass to the function. You need to show that first. – Pablo CG May 21 '20 at 21:55
  • Thanks Pablo. It is my first time trying to code through the google forms. So the whole idea is that I want to send a confirmation email when the form is submitted. The email should be an HTML email with pictures and colors and the recipient should enter his/her email in a cell in the form. Can you help me how to do this ? – Kowalski May 21 '20 at 22:00
  • Can you check this question? Maybe it gives you the orientation you need: https://stackoverflow.com/questions/28997714/google-script-send-form-values-by-email-error-cannot-read-property-namedvalue – Pablo CG May 21 '20 at 22:07

0 Answers0