[英]How to send HTML form data by email to an email ID by using JavaScript, without using server-side language, without using email client securely?
How to send HTML form data by email to an email ID by using JavaScript and without using server-side language and without using email client securely?如何通过电子邮件将 HTML 表单数据发送到电子邮件 ID,使用 JavaScript,不使用服务器端语言,也不安全地使用电子邮件客户端? I do not want any email client to pop open on clicking submit.
我不希望任何电子邮件客户端在单击提交时弹出。
It's very simple to send email by JavaScript:通过 JavaScript 发送电子邮件非常简单:
<textarea id="Body">
Mail Content
</textarea>
<button onclick="sendMail();">Send</button>
SendMail function:发送邮件功能:
function sendMail() {
var link = "mailto:me@example.com"
+ "?cc=myCCaddress@example.com"
+ "&subject=" + escape("This is my subject")
+ "&body=" + escape(document.getElementById('Body').value)
;
window.location.href = link;
}
You can call SendMail()
function on submit.您可以在提交时调用
SendMail()
函数。 Hope this help you.希望这对您有所帮助。
Your requirement basically says that you want to hit an smtp server directly and the mail should go from there.您的要求基本上是说您想直接访问 smtp 服务器,并且邮件应该从那里发送。
This would mean that Javascript should support a way to send data to an smtp server.这意味着 Javascript 应该支持一种将数据发送到 smtp 服务器的方式。
The default way to talk to a smtp server is via TCP/IP (you can use telnet on a smtp server, usually on port 25).与 smtp 服务器通信的默认方式是通过 TCP/IP(您可以在 smtp 服务器上使用 telnet,通常在端口 25 上)。
Since Javascript does not support TCP/IP directly it is not possible to do it directly from Javascript.由于 Javascript 不直接支持 TCP/IP,因此无法直接从 Javascript 进行。
This does not mean that这并不意味着
The above three methods seem to be the only ways I can think of to send a mail from Javascript.以上三种方法似乎是我能想到的从 Javascript 发送邮件的唯一方法。
Edit: There seems to be a TCPSocket https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket but it is not widely supported.编辑:似乎有一个 TCPSocket https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket但它没有得到广泛支持。
You might also want to look into flash, I don't know how long it will be widely supported though.您可能还想研究 flash,但我不知道它会被广泛支持多久。
It's very much deliberate that you aren't allowed to do this.不允许你这样做是非常刻意的。 If you could, everyone's browsers would be turned into infernal spam-spewing abuse machines.
如果可以的话,每个人的浏览器都会变成地狱般的垃圾邮件滥用机器。
From a web page, you can only choose between client-side mail, letting the user confirm what they're sending (and losing some proportion of respondants who aren't in a position to send mail), or a web-accessible server-side mail forwarder (either a third-party service or your own server in which case you have to work out the security yourself).从网页中,您只能在客户端邮件之间进行选择,让用户确认他们正在发送的内容(并失去一部分无法发送邮件的受访者),或者可以访问网络的服务器 -侧邮件转发器(第三方服务或您自己的服务器,在这种情况下,您必须自己解决安全问题)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.