使用 HTML 和 JavaScript 的联系表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22113091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Contact form using HTML and JavaScript
提问by user2922456
I've made a contact form for a website (using HTML and JavaScript), my problem is: how can I actually send the message (email) to the recipient?
我已经为一个网站制作了一个联系表格(使用 HTML 和 JavaScript),我的问题是:我怎样才能真正将消息(电子邮件)发送给收件人?
I found a way to do this in PHP, but I need a non-PHP solution. I've also heard I can so this using Outlook, but I'm not sure how I would do that.
我找到了一种在 PHP 中执行此操作的方法,但我需要一个非 PHP 解决方案。我也听说我可以使用 Outlook 做到这一点,但我不确定如何做到这一点。
回答by Afzaal Ahmad Zeeshan
No, using JavaScript and HTML, you cannot and can never send an email, sending an Email requires SMTP server settings which would enable you to communicate with an Email Sending Server (Outlook in your case). Then you can provide the parameters such as: To, From, Subject, Body, Attachment etc and the Email Service provider would take care of the rest and the email will be sent!
不,使用 JavaScript 和 HTML,您不能也永远不能发送电子邮件,发送电子邮件需要 SMTP 服务器设置,这将使您能够与电子邮件发送服务器(在您的情况下为 Outlook)进行通信。然后您可以提供诸如:收件人、发件人、主题、正文、附件等参数,电子邮件服务提供商将负责其余的工作,电子邮件将被发送!
Otherwise using Simple JavaScript you cannot send an Email to anyone and also you cannot get the email from anyone using just HTML and JavaScript. Its not what HTML and JavaScript are for. You're needing PHP or any other Server Side coding language for this thing!
否则,使用 Simple JavaScript 就无法向任何人发送电子邮件,也无法仅使用 HTML 和 JavaScript 从任何人那里获取电子邮件。它不是 HTML 和 JavaScript 的用途。你需要 PHP 或任何其他服务器端编码语言来做这件事!
回答by DDC
If you want user to compose an email, you can simply use
<a href="mailto:[email protected]">
on the webpage, clicking on this link would invoke Outlook on user's machine. See more on this here
如果你想让用户写一封电子邮件,你可以简单地<a href="mailto:[email protected]">
在网页上使用
,点击这个链接会调用用户机器上的 Outlook。在此处查看更多信息
If you want to use PHP, you can create a simple form in HTML with fields like from, to, subject, body etc. and on the server side, use PHP's mail() function to send the mail.
如果您想使用 PHP,您可以在 HTML 中创建一个简单的表单,其中包含 from、to、subject、body 等字段,并在服务器端使用 PHP 的 mail() 函数发送邮件。
回答by David
You should handle the operation of sending an email on the server side. One simple and easy non PHP solution would be for example nodemailer. You can create a simple express app then make it send email once it gets hit on a route for instance. There is a short blogabout it and many examples herethat handle gmail, outlook etc
您应该在服务器端处理发送电子邮件的操作。例如,一种简单易用的非 PHP 解决方案是nodemailer。例如,您可以创建一个简单的快速应用程序,然后让它在遇到路线时发送电子邮件。有一个关于它的简短博客,这里有许多处理 gmail、outlook 等的例子
回答by Tauciokas
PHP is the simplest option. I'm not too sure whether you can do it with Javascript and certainly not HTML. Check out http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/Its very simple
PHP 是最简单的选择。我不太确定您是否可以使用 Javascript 而不是 HTML 来做到这一点。查看http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/它非常简单