Submit Contact Form without using PHP

给你一囗甜甜゛ 提交于 2019-12-07 08:59:03

问题


I'm still a student and today our lecturer told us that the only way in order to submit a contact us form without having to use the mailto: function is to use PHP.

I swear that last year another lecturer showed us a way using only javascript.

Is it possible to submit a feedback/contact form using a basic form and javascript ? If so, do you mind sharing a sample example ?

Thanks in advance


回答1:


You can use JavaScript to redirect to mailto: with some parameters, but that isn't ideal. Also keep in mind that anything beyond an e-mail address in a mailto: URL is non-standard. While it will work for many browsers, it won't work for everything.

The best way to send e-mail is to do it server-side, using PHP or something else.




回答2:


A form is created/submitted by the browser based on HTML. JavaScript is commonly used to enhance forms (in many different ways). Basic forms send their data as a POST request. To do anything useful with the data you need server-side code to handle the POST request (such as PHP).




回答3:


You can't submit a form to javascript and expect it to do anything. You need a server side script in order to receive a form for processing. Mailto is a browser/os specific method and is not necessarily going to invoke anything. Javscript can process your form before going to the server for further processing, but like I said you need to submit to a server.




回答4:


Javascript cant capture anything without PHP or browser support. You need a server side script to receive a form and process it. Javascript without PHP or another server side script can't capture form.




回答5:


You can use a service like emailjs.com:

1) Configure EmailJS:

<script type="text/javascript" src="https://cdn.emailjs.com/sdk/2.2.4/email.min.js"></script>
<script type="text/javascript">
   (function(){
      emailjs.init("user_USERID");
   })();
</script>

2) Send the Email:

var service_id = 'my_mandrill';
var template_id = 'feedback';
var template_params = {
    name: 'John',
    reply_email: 'john@doe.com',
    message: 'This is awesome!'
};

emailjs.send(service_id,template_id,template_params);

It has a limit of 200 free emails per month, which will suite a resume/portfolio website. reCaptcha is supported.

EmailJS supports different Email providers (including a custom SMTP server), and provides you with logs and statistics.



来源:https://stackoverflow.com/questions/10181715/submit-contact-form-without-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!