Mailto Links

Basic

Open default mail program, create new message with the TO field already filled out.

<a href="mailto:someone@yoursite.com">Email Us</a>  

Adding a subject

Open default mail program, create new message with the TO and SUBJECT field already filled out. Essentially we are adding the parameter subject to the href value.

Spaces in the subject will probably work OK, but to be super-extra sure, you can replace spaces with "%20".

<a href="mailto:someone@yoursite.com?subject=Mail from Our Site">Email Us</a>  

Adding CC and BCC

Open default mail program, create new message with the TO, SUBJECT, CC, and BCC field already filled out. Essentially we are adding the parameters cc and bcc to the href value.

Also note that you add multiple values to CC and BCC by comma separating them.

<a href="mailto:someone@yoursite.com?cc=someoneelse@theirsite.com, another@thatsite.com, me@mysite.com&bcc=lastperson@theirsite.com&subject=Big%20News">Email Us</a>

Adding Body Text

Just add the body parameter into the ever-growing list of parameters we are using.

<a href="mailto:someone@yoursite.com?cc=someoneelse@theirsite.com, another@thatsite.com, me@mysite.com&bcc=lastperson@theirsite.com&subject=Big%20News&body=Body-goes-here">Email Us</a>

Comments

  1. User Avatar
    JMLeon
    Permalink to comment#

    Sadly, mailto’s are a call-for-spammers widely, so this is a curiosity more than something to use actually.

  2. User Avatar
    Jessi Hance
    Permalink to comment#

    @JMLeon: Not if you use Hivelogic’s Enkoder:

    http://hivelogic.com/enkoder

    I just used this today for a client, as a stop-gap till he can set up a contact form.

  3. User Avatar
    OldGuy
    Permalink to comment#

    Although people have been steadfast in their belief that the sky would fall, the world would end, and that their email boxes would overflow with spam if they were crazy enough to use mailto, I have yet to see the problem materialize. I have a number of smallish sites that have been up for years using mailto without ever having a problem. I do use contact forms on larger sites but only because I think it looks more professional.

    Excellent post Chris! Very handy stuff.

  4. User Avatar
    Kartlos Tchavelachvili
    Permalink to comment#

    I think you can use also the Paragraphs in the body message. Syntax = %0A%0A

    MailTo with multiline message in Body

  5. User Avatar
    Kartlos Tchavelachvili
    Permalink to comment#

    a href=”mailto:someone@yoursite.com?body=The message’s first paragraph.%0A%0ASecond paragraph.%0A%0AThird Paragraph.”

    • User Avatar
      Chuks
      Permalink to comment#

      @Kartlox Tchavelachvili Thanks for the paragraph syntax …

  6. User Avatar
    Brian Lang
    Permalink to comment#

    Caution: This may NOT work with all mail clients. I’ve had problems getting this to work with some mail clients in the past.

  7. User Avatar
    chaitanya T

    Thank you for the simple and effective approach for a contact option. Its nice.

  8. User Avatar
    Zeyad
    Permalink to comment#

    thanks

  9. User Avatar
    Don

    Thank you

  10. User Avatar
    Pete
    Permalink to comment#

    Thanks for reminding me about something I learnt originally in the 90s!

    • User Avatar
      Hamlegs Harold
      Permalink to comment#

      You mean learned?

    • User Avatar
      whatever
      Permalink to comment#
    • User Avatar
      Roger
      Permalink to comment#

      Learnt is ok in British English, but not in common use in the US.

    • User Avatar
      Sig Paulson

      Well, I’m glad you learnt it in the 90s. Some of us are still learning. What if you hadn’t and now wanted to? We’re not all computer junkies. This is what gets me. Because a computer tech or computer lover knows something they think everyone should already know or they are to be looked down on. Arrogance runs rampant in this field.

  11. User Avatar
    kunjan raychura
    Permalink to comment#

    Style links depending on file format

    /* external links */
    a[href^=”http://”]{
    padding-right: 20px;
    background: url(external.gif) no-repeat center right;
    }

    /* emails */
    a[href^="mailto:"]{
        padding-right: 20px;
        background: url(email.png) no-repeat center right;
    }
    
    /* pdfs */
    a[href$=".pdf"]{
        padding-right: 20px;
        background: url(pdf.png) no-repeat center right;
    }
    
  12. User Avatar
    pankaj
    Permalink to comment#

    I am using this code in ipad app and it’s working perfectly but the problem is that all work is done out side the app means after mail, app is closed.

  13. User Avatar
    BSK
    Permalink to comment#

    Can we attache any attachment with this. Please let me know.

  14. User Avatar
    kevin
    Permalink to comment#

    The end user must have a default mail prgm set up to work in windows.

  15. User Avatar
    Neil Monroe

    @premkumar: It doesn’t seem to work in Safari or Chrome (probably WebKit-based browsers, in general) if there are actual spaces in the querystring parameters to the mailto: link.

    If you replace the spaces with %20, then you should be back in business.

  16. User Avatar
    Ramesh

    Hello,

    I want a source code, when a visitor wants to click on “Email Offer” then a pop up is open with option of email clients, like – outlook, gmail and yahoo. When he/she select email client then it opens with my email id, Subject and offer. Or he/she wants their default email client in future when they visit again, a check box is also display in pop up.

  17. User Avatar
    Nabfars

    Hello
    Is there any way to align the text in mailto body to the right ?
    I am adding Arabic text in mailto body, Arabic text starts from right to left
    ill be great full for any help and suggestion
    Thanks

  18. User Avatar
    Klaus
    Permalink to comment#

    Great!
    Would I be able to use this code in Facebook, when writing on my wall?

  19. User Avatar
    Kate
    Permalink to comment#

    I would like to use a mailto command in SharePoint for use internally (Outlook 2010). I understand how to do the to, subject and body text, but I’d like to be able to dictate the background used (from those available in Outlook) so that users have a choice. Any ideas?

  20. User Avatar
    Juan JOcop

    I have a form that is a test, which asks for the name of a student who fills. I want to send an email warning that the test was completed and will include the student’s name. How do I include in HREF student’s name? Thank you

  21. User Avatar
    Trin
    Permalink to comment#

    It’s still very nice so far. Thanks
    my web is here
    also here

  22. User Avatar
    ThatGuySam
    Permalink to comment#

    Could you put HTML into the body this way?

    For example, bolding a word.

  23. User Avatar
    Robin
    Permalink to comment#

    Is there any way to include a variable in the mailto code e.g the filename of the page it appears on? It could then be used to receive comments?

  24. User Avatar
    John Sankey
    Permalink to comment#

    What I’d really like to do is to have the message sent as part of the mailto, so users don’t see a mail popup where they have to click send before it goes out. I know it’s astonishing to we geeks, but that really does confuse some people.

  25. User Avatar
    vipin
    Permalink to comment#

    Can we have HTML content in the mail.

    <a href=”mailto:abc@abc.com?subject=hello&body=< b >Make me Bold</ b >”
    when i do this the output in the body is:

    < b >Make me Bold< /b >

    But i want the text to be bold. is this even possible ?

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag