免责声明-我是初学者。如果这里没有简单的答案,我会很乐意复习正确的教程等。但我已经找了几天了,我不太明白。
用例:
答:访问者查看 Google 网站
我想:填写表格并选择提交
这样:输入的信息将填充到电子邮件中并发送到特定地址。
我做了什么:
创建 emailForm.html:
<html> <body> <script>google.script.run.processForm(document.getElementById('myForm')); </script> <div> <form id='myForm'> Subject:<input name='emailSubject' type='text'> <br><br> Body: <textarea name='emailBody' type='text'></textarea> <br><br> Add an Attachment: <input name='emailFile' type='file'> <br> <input type='button' value="Submit ZD Ticket" onclick='google.script.run.formSubmitReply()'> </form> </div> </body> </html>
创建了 sendEmail.gs:(注意:脚本不完整。我已添加我的评论)
function doGet() { // This function creates the form on the google site for the customer to use return HtmlService.createHtmlOutputFromFile('emailForm.html') } function formSubmitReply() { // This function is ran on the "Submit" button is selected and sends the email var subject = // ?? HELP: In a perfect world, it would be as easy as HtmlOuput.getInput('emailSubject') var body = // ?? HELP: In a perfect world, it would be as easy as HtmlOuput.getContent('emailBody') var attachment = // ?? HELP: In a perfect world, it would be as easy as HtmlOuput.getContent('emailFile') MailApp.sendEmail ('support@support.com', 'subject, body + attachment, {name:'Support Request'}); }
</p>
我的假设:
- 我认为我不需要访问任何数据库,并且我试图避免使用 Google 电子表格。我只想将输入值直接从表单发送到电子邮件地址。
我阅读了一篇建议记录表单值然后调用它的教程。但我不知道如何从表单中调用适当的输入或将这些输入添加到电子邮件中。教程中的示例函数:
function processForm(theForm) { Logger.log( // What goes here? ); }
谢谢大家的帮助!