Html form to mail
Here is an example of an HTML form that can be used to send an email using a mailto link:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea><br><br>
<input type="submit" value="Send Email">
</form>
This form has three input fields: name
, email
, and message
. When the user submits the form, the browser will open a new email composition window with the form data pre-filled.
Here's how it works:
- The
mailto
protocol is used to specify the email address to which the form data should be sent. - The
action
attribute is set tomailto:[email protected]
, where[email protected]
is the email address you want to send the form data to. - The
method
attribute is set topost
, which means that the form data will be sent to the email address using the POST method. - The
enctype
attribute is set totext/plain
, which means that the form data will be sent as plain text.
When the user submits the form, the browser will open a new email composition window with the form data pre-filled. The user can then edit the email and send it to the specified email address.
Note that this method is not secure, as the form data is sent in plain text and can be intercepted by third parties. If you need to send sensitive information, you should consider using a more secure method, such as using a server-side scripting language to send the email.
Here is an example of how you can use JavaScript to send the form data to an email address:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea><br><br>
<input type="submit" value="Send Email" onclick="sendEmail()">
</form>
<script>
function sendEmail() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var message = document.getElementById("message").value;
var emailBody = "Name: " + name + "\nEmail: " + email + "\nMessage: " + message;
window.location.href = "mailto:[email protected]?subject=Contact%20Form&body=" + encodeURIComponent(emailBody);
}
</script>
This code uses the window.location.href
property to open a new email composition window with the form data pre-filled. The mailto
protocol is used to specify the email address to which the form data should be sent. The subject
and body
parameters are used to specify the subject and body of the email, respectively.