我想發送電子郵件到某個位置[email protected]使用谷歌腳本 。我正在關注 - https://github.com/dwyl/html-form-send-email-via-google-script-without-server 以在我的網站上設置整個功能。使用谷歌腳本發送沒有服務器的電子郵件:無法打開文件錯誤
有一個在我的網站的HTML表單,我想發送電子郵件只要有人點擊提交按鈕在我的網站
這裏的HTML表單 -
<div id="content">
\t \t <h1>Contact Us</h1>
\t \t <h4>Fill out the form below and a representative will
contact you shortly.</h4>
\t \t <form id="gform" method="POST" action="https://script.google.com/macros/u/1/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec">
<div class="form-group">
<label for="exampleInputEmail1">Your Name (required)</label>
<input type="text" class="form-control" id="exampleInputEmail1" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Your Email (required)</label>
<input type="Email" class="form-control" id="exampleInputPassword1" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Subject</label>
<input type="text" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group">
\t <label for="exampleInputPassword1">Message</label>
\t <textarea class="message"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
這裏是script.gs文件 -
/******************************************************************************
* This tutorial is based on the work of Martin Hawksey twitter.com/mhawksey *
* But has been simplified and cleaned up to make it more beginner friendly *
* All credit still goes to Martin and any issues/complaints/questions to me. *
******************************************************************************/
var TO_ADDRESS = "[email protected]"; // where to send form data
function doPost(e) {
try {
Logger.log(e); // the Google Script version of console.log see: Class Logger
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
當我點擊填寫表格後提交按鈕,我得到這個 -
我得到同樣的畫面時,我在測試的Web應用程序點擊你最新的代碼。
我已經找到了 -
也有一些是我需要添加到裏面的形式我的HTML標籤爲「name」屬性,但它不是很清楚什麼補充。
我在哪裏設置此功能出錯?
可能有很多問題。你有沒有在你的gs腳本控制檯中設置觸發器?真的,我不認爲你可以在表單中使用動作標籤。您必須查找提交時單擊按鈕的時間,然後向網址發送ajax請求(https://script.google.com/macros/u/1/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec),這總是看起來不像上班。你部署正確嗎?將需要更多信息 – imox
當我在部署完成後打開它作爲「測試最新代碼的Web應用程序」鏈接時,保持按鈕的工作狀態不起作用。 –
我已經完成了與第1到第7點的教程中的完全相同的內容。除了這些說明,我沒有在我身邊添加任何內容。 –