我正在构建一个脚本,根据Google表单的填写方式向特定人员发送电子邮件。例如,如果选择方案A,则通过电子邮件发送Sabrina,如果选择方案B,则通过电子邮件发送Salem。我已将其设置为使电子邮件地址,主题行和电子邮件正文根据所选选项而更改,并且也希望对收件人名称执行相同操作,但出于某些奇怪的原因,收件人的姓名也是如此。 name正在应用于if-then子句的后续部分。例如,如果场景A的收件人应该是Sabrina,则收件人会显示为" undefined",而场景B则转发给Sabrina(而Salem则转换为场景C而不是Zelda)。 / p>
以下是我的代码 - 我在这里找不到令人难以置信的基本内容吗?所有其他变量都按预期正确分配。
var body = "Hi "+ recipient+", <p></p> You have a new research request, submitted by "+FormattedFirstName+" "+FormattedLastName+". Study details are listed below."";
if (emailSent != EMAIL_SENT) {
if (StudyType === "ScenarioA") {
var emailsubject = ("New " + StudyType + " Study Request");
var recipient = "Sabrina";
MailApp.sendEmail({
to: "sabrina@gmail.com",
subject: emailsubject,
htmlBody: body
});
sheet.getRange(startRow + i, 23).setValue(EMAIL_SENT);
}
else if (StudyType === ScenarioB") {
var recipient = "Salem";
var emailsubject = ("New " + StudyType + " Study Request");
MailApp.sendEmail({
to: "salem@gmail.com",
subject: emailsubject,
htmlBody: body
});
sheet.getRange(startRow + i, 23).setValue(EMAIL_SENT);
}
else if (StudyType === "ScenarioC) {
var recipient = "Zelda";
var emailsubject = ("New " + StudyType + " Study Request");
MailApp.sendEmail({
to: "zelda@gmail.com",
subject: emailsubject,
htmlBody: body
});
sheet.getRange(startRow + i, 23).setValue(EMAIL_SENT);
}
}
}
}