I am new to coding. This is my first query. Pardon me for mistakes.
I want to develop a simple code to take orders from customers. In the attached sheet - customers will select their products and a summary email should go to the customer's email id and the admin email id.
The email is getting sent with the correct subject line but the email body is incorrect.
The email body is - [object Object] - instead of the table with product details.
Below is the code. Please help. Thanks in advance.
"Sheet - Order tab"
function orderemail() {
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sh.getRange("A2:O38").getValues();
//var htmltable =[];
var TABLEFORMAT = 'cellspacing="2" cellpadding="2" dir="ltr" border="1" style="width:100%;table-layout:fixed;font-size:10pt;font-family:arial,sans,sans-serif;border-collapse:collapse;border:1px solid #ccc;font-weight:normal;color:black;background-color:white;text-align:center;text-decoration:none;font-style:normal;'
var htmltable = '<table ' + TABLEFORMAT +'">';
for (row = 0; row<data.length; row++){
htmltable += '<tr>';
for (col = 0 ;col<data[row].length; col++){
if (data[row][col] === "" || 0) {
htmltable += '<td>' + 'None' + '</td>';}
else if (row === 0) {
htmltable += '<th>' + data[row][col] + '</th>';
}
else {htmltable += '<td>' + data[row][col] + '</td>';}
}
htmltable += '</tr>';
}
htmltable += '</table>';
Logger.log(data);
Logger.log(htmltable);
var emailAddress = "chhedapriyank@gmail.com";
var emailAddress2location = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Order tab").getRange("C25");
var emailAddress2 = emailAddress2location.getValues();
// Send Alert Email.
var order = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Order tab").getRange("A2:K32");
var message = order.getValues();
var subject = 'New Order Alert';
var subject2 = 'Order Summary';
MailApp.sendEmail(emailAddress, subject, {htmlBody: htmltable})
MailApp.sendEmail(emailAddress2, subject2, {htmlBody: htmltable})
var reset = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Order tab").getRange("b3:j22");
reset.clearContent();
var reset2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Order tab").getRange("c25");
reset2.clearContent();
}