Mailto links

Useful HTML

The mailto protocol provides a convenient way to entice visitors to your website into contacting you. Clicking a mailto-link is designed to trigger an application external to the browser, the email client, that opens windows to a whole new level of personal contact. However, some drawbacks that may not be immediately apparent have led to irresponsible use of the possibility and a tainted reputation of the protocol.

From mailto message

To be of any use, a user must visit your site from his own computer with an email client installed that is registered with the browser and his own email address as the default sender. While this may be the natural situation for some, it certainly isn't that for those who rely on internet-café's for example for their surfing needs, or share their machine with family or roommates. People with computers at home and at work and different email addresses ‘installed’ on each, may visit your website from one station, and prefer to receive the reply at the other. And vice versa.

In short, interweaving email traffic with the open Internet takes more than a click. The most proper approach remains a serverside script, written in Perl, PHP, ASP, or YNI*, to take care of the actual sending, following the same old logic that there is an environment of known capabilities, and while browsers may live under mysterious circumstances with no email client in sight, they can send forms to the server all by themselves since HTML 2.0!

Not least, publishing email addresses online in a literal textual form should be avoided, as spammers continue to collect the addresses of their victims by scanning webpages for patterns in the text that match an email address. Common solutions use images or Javascript to print the address on the page, but they too are vulnerable to interpretation by the wrong interpretor.

What ’s in an address?

The email address may include the actual name of the recipient, whether a person or other entity. This is used by some email programs as display text in the address field, both in the sender's composition window and on the virtual enveloppe the receiver's side. The syntax is mailto:name<email> with the name between protocol and address, and < (less than) and > (greater than) delimiting the actual email (with its usual syntax a@b.c complete). And since we 're in a href attribute of a normal HTML element, they are to be escaped into &lt; and &gt; respectively to pass validation. Spaces and special characters in the name are possible, provided they are properly escaped; spaces before or after the name are also possible, but forbidden—or strongly discouraged. Some examples follow.


Besides the address of the recipient, some extra information can be passed along, by appending a ? (question mark) to the address, followed by name/value pairs of one or more of the following parameters, each joined by an = (equals), and all separated by an & (ampersand), depending on doctype escaped to &amp;. The names are case-insensitive, meaning that you are free to write Subject or SUBJECT, if you prefer to do so.

subjectA title for the message.
ccCopy recipients. One or more addresses, separated by ; (semicolon).
bccBlind copy recipients. One or more addresses, separated by ;.
bodyThe actual message. Text or escaped HTML.

The items may be put in any order. The total length of the href value is bound to a limit, but this depends on too many things to even estimate, but after a certain unreasonable amount characters will be ignored, or error messages appear. In Outlook Express, perhaps the most used Microsoft email client, the maximum length is said to be 456 characters.

Special characters need special encoding. A space becomes %20. A new line is %0d%0a, preceded by a carriage return.

According to rumours, some browsers use the value of the title attribute of the <a> element as a subject for the e-mail message, but this has not been verified.

Some samples

Clicking any of the following links should open an email window with some of the fields pre-filled.

  1. Email
  2. Email with name to Ann Example
  3. Email with subject
  4. Email with CC and BCC
  5. Email with body


<li><a href="mailto:an@example.com">Email</a></li>

 <a href="mailto:Ann%20Example&lt;an@example.com&gt;" title="Email to Ann.">
  Email with name
 to Ann Example

 <a href="mailto:an@example.com?subject=About%20last%20night">
  Email with subject

 <a href="mailto:an@example.com?cc=Copy1&lt;copy1@example.com&gt;;copy2@example.com&bcc=blind@example.com">
  Email with CC and BCC

 <a href="mailto:an@example.com?subject=About%20the%20body&body=Escape%20%22special%20characters%20and%0d%0anew%20lines.">
  Email with body