How to Add the Body to the Mailto Link
In HTML, you can create mailto links that open the default email client when clicked. By default, these links open a new email with the recipient’s email address populated. But what if you want to pre-fill the body of the email with a specific message? In this article, we’ll explore how to add the body to the mailto link using various techniques.
Steps to Add the Body
1. Add basic Mailto Link
The first step is to create a basic mailto link with the recipient’s email address. Here’s an example:
<a href="mailto:[email protected]">Send Email</a>
[email protected] with the actual email address of the recipient.
2. Adding the Body
To add the body to the mailto link, you can use the
body query parameter. Here’s an example:
<a href="mailto:[email protected]?body=Hello%20World">Send Email</a>
In the example above, we added the
body query parameter with the value “Hello World”. The
%20 represents a space character in the URL encoding format.
3. Encoding Special Characters
If your body text contains special characters or spaces, you need to properly encode them in the mailto link. Use URL encoding for special characters and replace spaces with
%20. For example:
<a href="mailto:re[email protected]?body=Hello%20%3Cstrong%3EWorld%3C/strong%3E">Send Email</a>
In this example, we encoded the HTML
<strong> tags and added them to the body.
Adding the body to the mailto link allows you to pre-fill email messages with specific content. Whether it’s a simple greeting or a more complex message, this feature can save users time and provide context when composing emails. Experiment with the examples provided and adapt them to suit your needs. Happy coding!
The single biggest problem in communication is the illusion that it has taken place.– George Bernard Shaw