问题
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