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
  2. Adding the Body
  3. Encoding Special Characters

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:

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:

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:

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
If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *