The Full mailto Link Syntax
For a small project, I had to create a smart mailto
link to make my life a bit easier. I wanted the mailto link to hold not only a to and the subject (I’d figured that much out) but a multi-lined body too. Turns out that is pretty darn easy to do. So, for my own reference, and yours, here’s a complete overview of everything possible with a mailto link.
There are a couple of variables you can use, which you’d have to do in standard URL format, remember to properly encode the &
if you care about the validity of your HTML, so you use &
in that case. Here’s the full mailto link syntax:
[code lang=”html”]<a href="mailto:info@example.com?subject=subject&cc=cc@example.com">mail link</a>[/code]
Here are the variables you can use in mailto links:
mailto: | to set the recipient, or recipients, separate with comma |
&cc= | to set the CC recipient(s) |
&bcc= | to set the BCC recipient(s) |
&subject= | to set the email subject, URL encode for longer sentences, so replace spaces with %20, etc. |
&body= | to set the body of the message, you can add entire sentences here, including line breaks. Line breaks should be converted to %0A . |
Some mailto link examples
A simple mailto link:
[code lang=”html”]<a href="mailto:info@example.com">mail link</a>[/code]
mailto link with subject:
[code lang=”html”]<a href="mailto:info@example.com?subject=email%20subject">mail link</a>[/code]
mailto link with multiple recipients:
[code lang=”html”]<a href="mailto:info@example.com,email@example.com">mail link</a>[/code]
mailto link with a CC:
[code lang=”html”]<a href="mailto:info@example.com?cc=email2@example.com">mail link</a>[/code]
A mailto link with message body already started:
[code lang=”html”]<a href="mailto:info@example.com?body=these%20mailto%20links%20are%20cool">
e-mail link
</a>[/code]
A mailto link with 3 lines of message body:
[code lang=”html”]<a href="mailto:info@example.com?body=these%20mailto%0Alinks%20are%0Acool">
mail links
</a>[/code]
A mailto link with 3 lines of message body and a BCC:
[code lang=”html”]<a href="mailto:info@example.com?bcc=mail2@example.com
&body=these%20mailto%0Alinks%20are%0Acool">
mailto links
</a>[/code]
As you can see, you can add as many of these as you want and stack them on top of each other. Remember that after the email address you’ll use a question mark to prefix the first variable, and ampersands ( & ) for each consecutive variable.
Happy coding and mailing!
Coming up next!
-
Event
International Search Summit 2024
November 14, 2024 Team Yoast is at Attending, Speaking International Search Summit 2024! Click through to see who will be there, what we will do, and more! See where you can find us next » -
SEO webinar
Webinar: How to start with SEO (November 19, 2024)
19 November 2024 Learn how to start your SEO journey the right way with our free webinar. Get practical tips and answers to all your questions in the live Q&A! All Yoast SEO webinars »
29 Responses to The Full mailto Link Syntax