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
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
Share Improve this question asked Apr 16, 2012 at 21:05 user1301836user1301836 2- 4 Can JavaScript email a form? – Josh Commented Apr 16, 2012 at 21:06
- This answer to this other SO question suggests to use formspree.io : stackoverflow./a/28536121/311288 – Thomas BDX Commented Mar 23, 2015 at 1:48
5 Answers
Reset to default 3You 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.
A form is created/submitted by the browser based on HTML. JavaScript is monly 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).
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.
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.
You can use a service like emailjs.:
1) Configure EmailJS:
<script type="text/javascript" src="https://cdn.emailjs./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: '[email protected]',
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.