我们正尝试编写一个发送电子邮件通知脚本,其中包含代理填写的表单数据的详细信息。它在第43行显示错误。正在发送电子邮件,但出现以下错误。另外,我们希望有一个固定的电子邮件地址,该电子邮件应与收件人一起发送至该地址。请告诉我我要去哪里错了。
var EMAIL_SENT = 'EMAIL_SENT';
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 1; // First row of data to process
var numRows = 18; // Number of rows to process
// Fetch the range of cells A2:R2
var dataRange = sheet.getRange(startRow, 1, numRows, 18);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 1; i < data.length; ++i) {
var row = data[i];
var ClientEmail = row[4];
var ClientPhone = row[5];
var SaleDate = row[2];
var name = row[3];
var LeadSource = row[6];
var LeadDate = row[7];
var PaymentRT = row[8];
var PaymentM = row[9];
var BalanceAD = row[10];
var BalanceED = row[11];
var TotalAP = row[12];
var SalesCategory = row[13];
var YourCommission = row[14];
var YourCommissiona = row[15];
var AdditionalInfo = row[16];
var emailAddress = row[1];
var message = "Agent Email: " + emailAddress +"\nSale Date: " + SaleDate +"\nClient Name: "
+ name +"\nClientEmail: " + ClientEmail +"\nClient Phone: " + ClientPhone +"\nLead Source: "
+ LeadSource +"\nLead Date: " + LeadDate +"\nPayment Received Today: " + PaymentRT +"\nPayment Mode: "
+ PaymentM +"\nBalance Due: " + BalanceAD +"\nBalance Expected Date: " + BalanceED +"\nTotal Amount Pitched: "
+ TotalAP +"\nSales Category: " + SalesCategory +"\nExpected Commission: " + YourCommission
+"\nExpected Commission Amt: " + YourCommissiona +"\nAdditional Info: " + AdditionalInfo;
var emailSent = row[17];
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = 'Sending emails from a Spreadsheet';
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 18).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}