我想发送电子邮件到某个位置[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点的教程中的完全相同的内容。除了这些说明,我没有在我身边添加任何内容。 –