I’ve been trying to figure out how to submit form data without using PHP code, is there a way? The mailto:
in HTML 5 only has the user fill the form out, then when submit
is clicked, it opens another application (mail app on desktop/laptop, and mail app on smartphones) and puts the data fields inside the message and makes the user click send in their mail, what do I do to at least just make the email sent to my email without the user having to take extra steps? Or being redirected to another app?
-
you don't have to use php for the form submission. You could even use JS for submitting a form. And the mailto haven't anything to do with a form submission. – Sumithran Jun 02 '19 at 16:01
-
You can use EmailJs or SMTPJs to sent the email using javascript. http://www.emailjs.com/docs/sdk/installation/ , https://smtpjs.com/ – Jijin P Jun 02 '19 at 16:02
-
this is what you are looking for https://stackoverflow.com/a/36656479/7796787 – Amospikins Jun 02 '19 at 16:08
-
1It would be better if you explain what you want to accomplish by doing this. It sounds you are trying to avoid using a server to process the data. – Juan Jun 02 '19 at 16:08
-
maybe this is what you want https://stackoverflow.com/questions/4782068/can-i-set-subject-content-of-email-using-mailto – Abed Putra Jun 02 '19 at 16:22
2 Answers
If I understand correctly, I think you can do the following. Grab the values of the inputs through javascript and send the email using window.location
with the input values.
HTML
<input type="text" id="subject">
<textarea id="body"></textarea>
<button type="button" id="send">Submit</button>
JS
$('#send').on('click', function(e) {
e.preventDefault();
subject = $('#subject').val();
body = $('#body').val();
window.location = "mailto:test@example.com?subject=" + subject + "&body=" + body;
});

- 1,746
- 2
- 17
- 36
HTML's mailto
process will prompt the user's mail service (outlook, thunderbird, etc.) to open, but none of your form data will be "processed". So, that might not be the best solution for you.
mailto
doesn't respond in exactly the same way for every browser and every email client.- Using this method allows your site visitor to send any information they want to you just by editing the email before they send it to you.
Example: I fill out your form and hit the send (or submit) button. My mail client (Thunderbird) opens with all of the address to, from, subject, and message fields already filled in. I erase the message field and put in "something else". Then I send it to you. You open your email and ... - You are providing your email address to a gazillion webcrawlers who scrub the internet for email addresses to send scams, junk, etc. to on a daily basis.
submit form data without using PHP code
The primary purpose of your script is to process the information before it's sent. The script will parse the data, removing information bits that are ordinarily used in programming. Like, potential Malware code. A form/email script (like this) can be written in any language that will communicate directly with the server (provided that the language is on the hosting server)... PHP, CGI/Perl, (maybe javascript?), etc.
What you are looking to do, is match the values in your form to the users answers and then relay that informaiton. In order to do that, you will want to first create your form. When your site visitor fills out the form and hits submit, you want the data to be sent to a script which will check the data, then complete the email fields (to, from, subject, message) and then send it through the server (without exposing your email address to the world).
This is probably a task for an intermediate programmer. That doesn't mean that a "Noob" can't do it, just that it will require a bit of learning to get there. Compare examples online until you find one that makes sense to you.

- 763
- 5
- 16