Home > Software design >  Apps script to get automated html email on google form submit
Apps script to get automated html email on google form submit

Time:10-12

I want to send a confirmation email whenever a customer submit a booking via google form. The content of the email will be partly based on the number of people and timeslot the customer chosen. I succeed in triggering an email, but the email content is [object Object]. What did i do wrong?

function sendBookingConfirmationEmail(e) {

  var html = HtmlService.createTemplateFromFile("confirmationEmail.html");
  var emailTo = e.response.getRespondentEmail();
  var bookingParameters = e.response.getItemResponses();

  var bookingName = bookingParameters[0].getResponse()
  var numberOfTele = bookingParameters[1].getResponse()
  var numberOfKids = bookingParameters[2].getResponse()
  var numberOfAdults = bookingParameters[3].getResponse()
  var scheduledSlot = bookingParameters[4].getResponse()

  html.numberOfKids = numberOfKids;
  html.numberOfAdults = numberOfAdults;
  html.numberOfTele = numberOfTele;
  html.scheduledSlot = scheduledSlot;

  var htmlText = html.evaluate().getContent();

  var emailSubject = "BOOKING CONFIRMATION";
  var options = { htmlBody: htmlText }

  if (emailTo !== undefined) {
    GmailApp.sendEmail(emailTo, emailSubject, options);

  }

}


<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p>  <?= numberOfKids ?> <?= numberOfAdults ?> Your booking has been confirmed.  etc...</p>

    <p> Best Regards<br>
    Team</p>


  </body>
</html>

CodePudding user response:

Based on this thread, try changing this line

GmailApp.sendEmail(emailTo, emailSubject, options);

to

GmailApp.sendEmail(emailTo, emailSubject, "", options);

I tested it and it works.

CodePudding user response:

from documentation ,the full signature for the function is the folowing :

sendEmail(recipient, subject, body, options)

I supsect that you pass the options variable as the body

As workaround, you can put every argument into an object :

sendEmail({recipient:emailTo , subject: emailSubject, htmlBody: htmlText})

  • Related