How to link submit button to email in html
To link a submit button to an email in HTML, you can use the mailto
protocol. Here's an example:
<a href="mailto:[email protected]" target="_blank">
<input type="submit" value="Send Email">
</a>
In this example, the href
attribute is set to mailto:[email protected]
, which will open the default email client on the user's device with the email address [email protected]
pre-filled in the "To" field.
You can also add additional parameters to the mailto
link to specify the subject, body, and other details of the email. For example:
<a href="mailto:[email protected]?subject=Hello%20World&body=This%20is%20a%20test%20email">
<input type="submit" value="Send Email">
</a>
This will open the email client with the subject "Hello World" and the body "This is a test email".
Note that the mailto
protocol is not supported by all email clients, and some users may not have a default email client set up on their device. Additionally, some email clients may not support the subject
and body
parameters.
Alternatively, you can use a JavaScript library or framework to send an email programmatically. For example, you can use the EmailJS
library to send an email from your HTML page:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/email.min.js"></script>
<form>
<input type="submit" value="Send Email">
</form>
<script>
emailjs.send('[email protected]', 'your-email-password', 'Hello World', 'This is a test email');
</script>
This code sends an email using the EmailJS
library, which requires you to set up an account and obtain an API key.