JavaScript mailto: with subject and body – [Solution]

In this tutorial we are going to see how to write a javascript mailto function so that both the subject and body will be Pre-filled?

Many of us might have used mailto function just like below (passing only the mail id):

mailto: someone@example.com

But there are other parameters also you can send it along with that, those are:

1. cc
2. bcc
3. subject
4. body

And one more important thing, you can also send to multiple recipients (see the below example):

mailto: someone1@example.com, sometwo@example.com

Now lets form the entire structure including all the above parameters

mailto:example@example.com, test@examplecom?cc=cc@example.com&bcc=bcc&example.com&subject=Your%20Subject&body=type%20your%20message%20here

 

Make sure you have encoded the text in Subject line and Body. You can see there is a %20 between texts in subject and body right?. Its nothing but space between the texts.

For your convenience, I have given an example code. Just copy and paste and have a try:

<html>
<head>
</head>
<body>
<a href="mailto:example@example.com,test@exanoke.com,funny@fun.com?cc=cc@example.com&bcc=bcc&example.com&subject=Your%20Subject&body=type%20your%20message%20here">Mail</a>
</body>
</html>

Thanks.

Leave a Reply

Theme: Overlay by Kaira
Agurchand