免責聲明 - 我是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