It’s often very useful to have create a link on your website that when clicked on open a new outgoing email message, for example when you create a “contact us” button. Such link is created using the <a> html tag and the mailto URL scheme.
In its most basic and commonly used form the mailto link indicates the email address of the intended recipient. For example:
<a href=“mailto:[email protected]”>Contact Us</a>
This result in a link that looks like Contact Us.
In fact the email address in the mailto link is even optional, if you leave it out (so the href simply says “mailto:”), a new outgoing email window will be opened in the users default email client. This is useful when you want to create a share link that users can click on so they can send an email to the person of their choosing.
Specifying Details
In addition to the email address you can provide other information as well. Each standard email header field can be added to the mailto URL, e.g. “subject”, “cc” and “body”. Each header field and value is specified as a query term in the href property of the link tag.
Basic
To open up an email client with the email address already filled out use the following link:
<a href=”mailto:[email protected]”>Contact Us</a>
Adding A Subject
Open the default email client with the “TO” field and “SUBJECT” field already filled out is done by adding the parameter subject to the href value.
Note: spaces in the subject line will work but to make sure it is recommended that you replace them with %20.
<a href=”mailto:[email protected]?subject=Mail from Our Site”>Contact Us</a>
or when spaces are replaced with the %20 tag
<a href=”mailto:[email protected]?subject=Mail%20from%20Our%20Site”>Contact Us</a>
Adding CC and BCC
Adding a CC and / or BCC can be done also. To create a new email message create with the TO, SUBJECT, CC, and BCC field already filled out use the following mailto code.
<a href=”mailto:[email protected][email protected], [email protected], [email protected]&[email protected]&subject=Mail%20from%20Our%20Site”>Contact Us</a>
Adding Body Text
To fill out the body or message of the email just add the body parameter into the growing list of parameters.
<a href=”mailto:[email protected][email protected], [email protected], [email protected]&[email protected]&subject=Mail%20from%20Our%20Site&body=Body-goes-here”>Contact Us</a>