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.
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!
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
email@example.com complete). And since we 're in a
href attribute of a normal HTML element, they are to be escaped into
> 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
&. The names are case-insensitive, meaning that you are free to write
SUBJECT, if you prefer to do so.
|A title for the message.|
|Copy recipients. One or more addresses, separated by |
|Blind copy recipients. One or more addresses, separated by |
|The 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.
Clicking any of the following links should open an email window with some of the fields pre-filled.
<li><a href="mailto:firstname.lastname@example.org">Email</a></li> <li> <a href="mailto:Ann%20Example<email@example.com>" title="Email to Ann."> Email with name </a> to Ann Example </li> <li> <a href="mailto:firstname.lastname@example.org?subject=About%20last%20night"> Email with subject </a> </li> <li> <a href="mailto:email@example.com?cc=Copy1<firstname.lastname@example.org>;email@example.comfirstname.lastname@example.org"> Email with CC and BCC </a> </li> <li> <a href="mailto:email@example.com?subject=About%20the%20body&body=Escape%20%22special%20characters%20and%0d%0anew%20lines."> Email with body </a> </li>