Submit Contact Form without using PHP
Asked Answered
C

5

5

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

Candiot answered 16/4, 2012 at 21:5 Comment(2)
Can JavaScript email a form?Jeniferjeniffer
This answer to this other SO question suggests to use formspree.io : https://mcmap.net/q/582441/-email-contact-form-without-phpSpue
P
3

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.

Privative answered 16/4, 2012 at 21:8 Comment(1)
so there is no way that the email can be sent without opening the client's default mail viewer and having them click send ?Candiot
S
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).

Siderostat answered 16/4, 2012 at 21:17 Comment(0)
T
1

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.

Thorley answered 16/4, 2012 at 21:27 Comment(0)
A
1

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.

Angers answered 16/4, 2012 at 21:36 Comment(0)
L
1

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: '[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.

Lionhearted answered 10/12, 2018 at 23:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.