Google脚本,通过表单提交触发表单详细信息 [英] Google script, send email with form details triggered by form submit

查看:761
本文介绍了Google脚本,通过表单提交触发表单详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function sendFormByEmail (e)
{
  var email = "inputemail@address";
  var txt = "";
  for (var field in e.namedValues) {
    txt += field + ' :: ' + e.namedValues[field].toString() + "\n\n";
  }

  MailApp.sendEmail(email, "input email subject", txt);
}

我相信以下工作(当填写有效的电子邮件地址时)。然后,我复制并粘贴上述<希望表单细节可以通过电子邮件发送给两个不同的人。然后上述不起作用。试图删除它的第二个副本。这并没有解决问题。现在当我测试运行时出现以下错误:TypeError:无法从undefined读取属性namedValues。 (第5行,电子邮件提交表格文件)。我完全困惑,因为我非常确定这是与以前工作的脚本相同的脚本。我必须透露这是我十多年来第一次尝试编写脚本。我不是程序员 - 我是新手,从未正式研究过编码。任何人都可以向我解释外行对我可能发生的事情吗?或者在适当的情况下更正脚本?感谢您的时间。

I believe the following worked once (when filled with a working email address). I then copied and pasted exact same script below the above & added a different email in the hopes that form details could be emailed to two separate people. Then the above didn't work. Tried deleting the second copy of it. This didn't resolve problem. Now am getting the following error when I test run it: TypeError: Cannot read property "namedValues" from undefined. (line 5, file "Email submitted form"). I'm utterly perplexed as I'm pretty sure this is the same script as what was working previously. I must disclose this is the first time I've tried scripting anything in over a decade. I am not a programmer - am a novice, never formally studied coding. Would anyone be able to explain what might be happening in layman's terms to me? Or correct the script if appropriate? Thanks in advance for your time.

推荐答案

你需要确保你的函数有一个On表单提交触发器集,并且你将有在Apps脚本编辑器中执行一次(如果在设置触发器时没有提示),接受使用从您的帐户发送电子邮件。

You will need to ensure there is an On form submit trigger set for your function, and you will have to execute it once in the Apps Script Editor (if you are not prompted when setting the trigger), to accept the use of sending email from your account.

如果您是寻找发送邮件给多个人,只需用逗号分开列表;

If you are looking to send the mail message to multiple people, just comma separate the list;

例如

// broken up for clarity
var email = "inputemail@address";
email += ",";
email += "secondrecipient@address";
// add the email address collected from the form
email += ",";
email += e.namedValues['Username'];

这篇关于Google脚本,通过表单提交触发表单详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆