mailto() basic guide

February 25th, 2007

mailto.jpg

Many of you have wondered how do those cool links work, those that launch your default mailing client with an email ready to be sent. Well so did I until some time now when I needed such a link for one of my projects. I do realize that you can find plenty information on this subject online but I wanted to put together an easy to use guide to create your own mailto() links.

Let’s start with the beginning: mailto() is used with the almighty <a> HTML tag like shown below. This is quite simple and if you add an anchor to it you get a simple link. This is useful for most purposes, but you can evolve:

<a href=”mailto:user@domain.com”>

To use multiple recipients you can use something like this, and you can add as much recipients as you please separated by “,”.

<a href=”mailto:user1@domain.com,user2@domain.com”>

Also if you wish to send a copy or a blind copy of the email to a certain address you can use the syntax below. After all the main recipients are added you must use “?” after that you just separate commands by “&”. Remember to use “?” just once after all the main recipients.

<a href=”mailto:user1@domain.com?&cc=user2@domain.com”>

Here is another example:

<a href=”mailto:user1@domain.com?&cc=user2@domain.com&bcc=user3@domain.com”>

Using the above commands you can create the basic structure for an email but there’s more. For example you can choose the title and put some text in the body of the email.

The following line creates an email to user@domain.com with the title “Test subject”.

<a href=”mailto:user@domain.com?subject=Test%20subject”>

Furthermore, you can add some standard text in the body:

<a href=”mailto:user@domain.com?subject=Test%20subject&body=Test%20body”>

You might have noticed the “%20″ sign between words within the title or the body. That symbol is used by the HTML to mark an empty space. You don’t have to include it because the empty space will be transformed automatically. On the other hand if you want to mark a new line you have to use “%0A” like so:

<a href=”mailto:user@domain.com?& body=A line%0A%0AAnother line%0A%0AThird line”>

Tips & Tricks:

A good suggestion is to encode your e-mail address in order to limit spam to the given email address, or maybe you want to encode the whole mailto() code. A good way to do this is to follow this link.

It’s good to know all the information above in order to understand the syntax of mailto() but in the end I strongly recommend that you use links like this to generate the code for you and then ecrypt it and use it.

Good luck and keep experimenting!

Example: Sample link

Featured tags:

Sphere this entry»

Comments

  1. nogg3r5:

    Can I suggest that you highlight your code somehow? It would make the article about 1 million times easier to read!!

  2. Brayn:

    Thanks for the heads-up! I’ll try to make it more user-friendly!

  3. nogg3r5:

    Thats loads better, I prefer not to read the bulk of the article and to just skim the code, then read up on parts that arent obvious, this really helps

  4. Bogdan Popa:

    Right you are. Thanks again for the notice!

Allowed XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Please post your comment in English only so we can all understand. Comments in other languages (excepting trackbacks) will be declined. Also, comments containing foul language or offensive words will be censored or declined as well.