免责声明 - 我是BEGINNER。如果这里没有简单的答案,我会很乐意回顾正确的教程等,但我一直在寻找几天,我不明白这一点。使用Google协作平台/脚本:将表单中的输入值发送到支持电子邮件地址
使用案例:
为A:访问者查看谷歌网站
我想:填写表格,然后选择提交
使:输入的信息将填充的电子邮件并发送到特定地址。
我所做的:
创建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 ('[email protected]', 'subject, body + attachment, {name:'Support Request'}); }
我的假设:
- 我不认为我需要访问任何数据库和我试图避免使用谷歌电子表格。我只想将输入值从表单直接发送到电子邮件地址。
我读了一篇教程,建议记录表单值然后调用它。但我不知道如何从窗体调用适当的输入,或者将这些输入添加到电子邮件中。从教程示例功能:ALL任何帮助
function processForm(theForm) { Logger.log( // What goes here? ); }
谢谢!
嗨Corey G!感谢您的快速回复。我按照您的建议进行了更改。 ** NEW ** emailForm.html:http://screencast.com/t/VAP0rZIQ ** NEW ** sendEmail.gs:http://screencast.com/t/NRtCUuC9m58w当我执行时,我收到**错误:“TypeError:无法从undefined读取属性”emailSubject“(第7行)”** Capture:http://screencast.com/t/mV7OKDAD4f9e * Ideas *? – Brad 2012-07-31 17:33:22
我刚刚测试了你的代码,就像发布一样,它工作正常。你确定你刷新了页面吗? – 2012-07-31 19:46:40
我刚刚从网站重新测试(我正在测试脚本页面),它正在工作!谢谢! – Brad 2012-07-31 20:32:19