How can I send a form's contents over e-mail w

2019-08-22 13:06发布

I've got a feedback HTML form, the results of which I need to send to an e-mail address. How do I do that in JavaScript?

11条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-22 13:57

You have two options:

1) Use a mailto link. Javascript isnt really necessary although you could use Javascript to "click" the mailto link. This will cause the user's email client to open with a new email prepopulated with the recipient's email address. mailto links There are numerous reasons why mailto links are unreliable (see comments below). They are not recommended.

2) Submit a form back to the server then send the email from the server. Whatever the server side code is (php, c# etc) should have the ability to send email. This way you can guarantee the email was sent.

You cannot silently send email from the browser. It has to either happen with user assistance or on the server.

查看更多
不美不萌又怎样
3楼-- · 2019-08-22 13:59

You cannot send mails with client side javascript. Submit the form to a server side script like PHP/JSP/ASP etc and send mail from that script.

查看更多
一纸荒年 Trace。
4楼-- · 2019-08-22 14:01

Your only option is to submit it is a regular form and then send on server side.

查看更多
萌系小妹纸
5楼-- · 2019-08-22 14:02

Impossible, for only with javascript, but with the help of server side script, you could.

Please take a look php mail function here

查看更多
▲ chillily
6楼-- · 2019-08-22 14:03

One way you can attempt to do this is have a

<form action="mailto:example@example.com">

when submitting this will attempt to email the form to the given email address, this is a pretty nasty solution as it relies on the client having a correctly configured mail client. Also you have no controll over the presentation of the email. see Beware of Form Mailto Action for some of the pitfalls.

查看更多
登录 后发表回答