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:
1 |
Replace [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:
1 |
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:
1 |
In this example, we encoded the HTML <strong>
tags and added them to the body.
Conclusion
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