Promblem with <form> tag in HTML

102 Views Asked by At

I have face this problem tag. Every time i click enter after filled any one of the text area in the form, it redirect me to my email. Why?? I want clear one thing that I'm totally a beginner.

<form action="mailto:[email protected]" Method="post" Enctype="text/plain">

Image

Ps: I'm using "Atom"

3

There are 3 best solutions below

0
AudioBubble On

Mailto link is a type of HTML link that activates the default mail client on the computer for sending an e-mail.

0
Anis R. On

Let's answer your questions one by one:

1- Why does your form automatically submit when you hit enter?

The action property of your form is the URL to which your form will be submitted. And by default, when you hit enter in a form, the form will automatically submit.

2- Why does it open your email app on form submit?

Well, your form's action is set to mailto:[email protected], and mailto: URIs always redirect to your default mail app.

If you want your web application to send an email automatically instead, you will need some server-side work. Implement a backend script (PHP, C#, whatever), and modify your form's action so that it submits to that script instead of mailto:.

0
Run_Script On

Assuming that by it redirect me to my email you mean that it opens your email client, that is the expected behaviour. A mailto link opens your email client and writes the email address into the To field, as well as a subject and message if specified.

As this doesn't seem to be the behaviour that you are expecting, I'm assuming that you want the form to actually send an email to that email address. You'll need to do this differently.

In the action attribute, put the name of a .php file. In this PHP file, access the form data using $_POST, and send an email using the mail() function.