The Full mailto Link Syntax

sending email through mailto linksFor 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 validity of your HTML, so you use & in that case. Here’s the full mailto link syntax:

<a href="mailto:info@example.com?subject=subject&cc=cc@example.com">mail link</a>

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:

<a href="mailto:info@example.com">mail link</a>

mailto link with subject:

<a href="mailto:info@example.com?subject=email%20subject">mail link</a>

mailto link with multiple recipients:

<a href="mailto:info@example.com,email@example.com">mail link</a>

mailto link with a CC:

<a href="mailto:info@example.com?cc=email2@example.com">mail link</a>

A mailto link with message body already started:

<a href="mailto:info@example.com?body=these%20mailto%20links%20are%20cool">
  e-mail link
</a>

A mailto link with 3 lines of message body:

<a href="mailto:info@example.com?body=these%20mailto%0Alinks%20are%0Acool">
  mail links
</a>

A mailto link with 3 lines of message body and a BCC:

<a href="mailto:info@example.com?bcc=mail2@example.com
  &body=these%20mailto%0Alinks%20are%0Acool">
mailto links
</a>

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!

Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

29 Responses

  1. ArjanBy Arjan on 27 October, 2008

    The examples with body texts contain spaces, while a URL cannot contain them. They should be converted to %20 ;)

    • Joost de ValkBy Joost de Valk on 27 October, 2008

      Fixed, practice what you preach, I know ;)

  2. Eric FickesBy Eric Fickes on 27 October, 2008

    Here’s the mailto RFC for more reading on mailto.

  3. André ScholtenBy André Scholten on 27 October, 2008

    Nice article, but be aware of the mailto flaws, only use it when nothing else is possible.

    • Joost de ValkBy Joost de Valk on 27 October, 2008

      @André: that’s for forms, I actually use stuff like this to quickly email all the commenters on a post, for instance.

      • André ScholtenBy André Scholten on 27 October, 2008

        @Joost: forms do give a lot more trouble when used with mailto’s in their action attribute. But the same goes for plain mailto links. The browsers behavior on a mailto link isn’t defined in some sort of standard. If I click on a mailto link on my fresh installed laptop it isn’t working because I only use webmail. Windows can’t find a proper application to send the mail.

        But yes: they work fine if you only use them for personal reasons.

  4. lazy drunkBy lazy drunk on 27 October, 2008

    Ring ring.. The 90s called and want their sick html-code skills back. Just kidding. Great stuff.

  5. Maxime GuernionBy Maxime Guernion on 27 October, 2008

    Thanks for theses advices ! Where did you find theses funky characters images ?

    • Joost de ValkBy Joost de Valk on 27 October, 2008

      @Maxime I’ve got a while pile of them :)

      • Maxime GuernionBy Maxime Guernion on 28 October, 2008

        @Joost : If they are royalty free, can you send them to me? :) Thank you in advance.

  6. impNERDBy impNERD on 28 October, 2008

    It should also be noted that bots can and do crawl pages and spam mailto links. if you absolutely must use mailto, be sure to change the @ to something like [at] and tell visitors to change it before mailing.

    • Joost de ValkBy Joost de Valk on 28 October, 2008

      @impNERD: yeah I usually do not use these in public, and if I do, I ROT13 the entire script piece.

  7. Joacim BoiveBy Joacim Boive on 28 October, 2008

    Actually mailto links aren’t a good way to go. This requires that the visitor has a proper setup of their email client, if they don’t have a default email client installed (or it’s configured wrong) the mailto-links won’t work.

    Mailto-links may seem convenient, but it’s bad practice. Forms, how ever boring, is the way to go.

    My 2C!

    /J

  8. Joost de ValkBy Joost de Valk on 28 October, 2008

    Once and for all :) I use these mailto links for my OWN use in my OWN internal applications, not on the front end! (And I know you all mean your comments lovingly and you ARE helping the readers here :) )

  9. lazy drunkBy lazy drunk on 28 October, 2008

    ooooo. now I see.

  10. GregBy Greg on 28 October, 2008

    Code textareas are broken in IE7.

    What about those of us who use GMail? (Plus, there’s no tastier spider food than a juicy mailto: link…)

  11. TertiusBy Tertius on 29 October, 2008

    Was just looking for this in some form processing that I’m doing for a local educational client.

    I didn’t even look for this, just stumbled accross your post!

  12. suzanneBy suzanne on 4 November, 2008

    ah this is helpful for sure! much thank you’s!

  13. Debugged Interactive DesignsBy Debugged Interactive Designs on 25 November, 2008

    We created a free PHP class, which hides mailto links from spam harvesters =
    http://www.debuggeddesigns.com/open-source-projects/mailto

  14. GrantBy Grant on 19 August, 2009

    Can anyone please tell me why, in my mailto links, they break when they hit my & conversions?

  15. ShawnBy Shawn on 22 October, 2009

    I have been looking all over and I understand that I can’t use a href mailto and have the Body be a html link. I have read this all over. But I am looking for a way around it. I dont want to send a server side email. I am using this as part of an internal use, and need to open the email client on the local machine but I have the need to put a Link in the Body of the email. The only way that I have seen to do this so far is to use a Java script. I am working from ASP. should I use Java script to do this and does any one know of a good site that can explain in full detail how to do this ?

    Thanks For all the good info here.

    • Eric FickesBy Eric Fickes on 22 October, 2009

      Shawn, you can do this with encoding the HTML, but it’s up to the email client to recognize and render as HTML.

      EX :

      click mailto

      If you save that to an HTML file, you should see a “click mailto” link. When the message pops up, my email client shows the HTML link, but doesn’t render as clickable.

      HTH

      • Eric FickesBy Eric Fickes on 22 October, 2009
        • ShawnBy Shawn on 22 October, 2009

          I really appreciate your Help.

          That sort of works but when Outlook 2007 opens it puts this in the body

          click me

          between the ‘ ‘ is hyperlinked and underlind but it still shows the surrounding stuff in plain text It seems like some thing alot of people are looking to do but not very many clear cut answers. I understand this is due to the multitude of email clients out there. And i understand the need to encode but in my situation it is all internal and not even open to public viewing.

          • ShawnBy Shawn on 22 October, 2009

            click me” sorry the link showed as a link i ment to display the whole thing

  16. ShawnBy Shawn on 22 October, 2009

    click me
    maybe this will show it like I ment : )

Trackbacks

  1. 89 Ways for You to Become the Coolest Programmer in the World…

    Since there are dozens of posts on becoming a better developer, but no single post with all the advice you need, perhaps, you’ll find this short guide useful.
    1. Learn the Skills You Need

    Learn the programming basics

    “The goal of this guide is to b…