How to send email from JavaScript HTML using mailto

Here is a simple example to send an email using JavaScript - mailto. You can use this code with any control (example - button) and even any event (example - on click).

This code will invoke the user's default email client with the required parameters pre-filled (like email address, subject, and message body) and the user just needs to click send to send the email.

Note - It is not possible to directly send email from JavaScript, you can only invoke/open the default email client.

Code Type: Specify only Email ID
window.open('mailto:useremail@domain.com');
Code Type: Specify multiple Email IDs (separate id's by comma(,) or semi-colon(;) )
window.open('mailto:useremail1@domain.com,useremail2@domain.com');
Code Type: Specify Email ID, Subject, Body
window.open('mailto:useremail@domain.com?subject=This is the email subject&body=This is the email body');

This is not an AI-generated article but is demonstrated by a human.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!