VOL. I · NO. 1
PACKAGE v0.3.0
✦ TECHNOLOGY SPECIAL

The Internet Times

All the protocols that are fit to fix.

HTML guide · RFC 6068

Encode a mailto subject and body correctly

A valid mailto link keeps its separators readable and encodes the message content. Spaces, punctuation, and line breaks each need the correct percent code.

The structure

Separate the fields before you encode them

Start with mailto: and the recipient. Add ?subject= before the subject. Add &body= before the body. The question mark and ampersand are structural separators, so do not encode them.

mailto:hello@example.com?subject=encoded value&body=encoded value
The red segments are separators. Only the subject and body values are encoded.

Encoding table

Use percent codes for reserved characters

Encode the text as UTF-8, then replace reserved bytes with percent codes. Do not replace spaces with literal spaces. %20 is clearer than + across mail clients.

CharacterPlainEncoded
Space %20
Ampersand&%26
Question mark?%3F
Colon:%3A
Comma,%2C
Line breaknew line%0A

Tested example

Encode the text, not the meaning

This example preserves an ampersand, a question mark, a colon, a comma, and two line breaks. The decoded draft reads exactly like the original message.

Mailto URL
mailto:hello@example.com?subject=Budget%20%26%20timing%3F&body=Hi%20team%2C%0A%0ACan%20we%20talk%20at%202%3A30%3F
Ready-to-paste HTML
<a href="mailto:hello@example.com?subject=Budget%20%26%20timing%3F&amp;body=Hi%20team%2C%0A%0ACan%20we%20talk%20at%202%3A30%3F">Email the team</a>

Subject

Budget & timing?

Body

Hi team, Can we talk at 2:30?

HTML source

Escape the separator one more time in markup

A raw mailto URL uses & between query fields. Inside an HTML attribute, write that separator as &amp;. The browser turns it back into one ampersand before opening the mail client.

Do not encode the whole URL with encodeURIComponent(). That would also encode mailto:, the question mark, and the field separators. Encode each subject or body value separately, then assemble the URL.

Client check

Test the final draft, not only the string

Open the link in the browser and email clients that matter to your audience. Confirm the recipient, subject, punctuation, and blank lines. A syntactically valid link can still behave differently when a client applies its own parsing rules.

Live output preview

Ready to build

Build the encoded link without hand-editing percent codes

The free smart-mailto generator encodes each field and returns both the URL and escaped HTML. It runs in your browser.

Open the mailto generator