HTML MailTo Commands: A Step By Step Tutorial in Creating a MailTo Link

HTML MailTo Commands: A Step By Step Tutorial in Creating a MailTo Link
Page content

Background of HTML MailTo Commands

Back in the late 90s and the first half of this decade when webpages were more static than dynamic, HTML MailTo links were used in webpages for feedback from visitors. However they were prone to many attacks similar to the ones caused by the famous love-bug and Melissa worms.

As pages became more dynamic, developers began using forms instead of the HTML MailTo attribute. This gave the developers more control over the data passed to the server, with better security.

Before proceeding on how to create a MailTo link, the webpage developer should be aware that not everyone who wants to send feedback using the link will be using an email client or an email reader like Microsoft Outlook or Mozilla Thunderbird. So it is a good practice to create a script to redirect visitors to one of those sites that provide an email client, so that they can use the MailTo feature.

How to Create and Configure the HTML MailTo in Your Webpage:

For sending an email, three main fields are required. They are:

  1. The email address of the person to whom the email has to be sent,

  2. The subject,

  1. The body of the email.

In addition to the above three fields, fields like Cc(Carbon Copy), Bcc(Blind Carbon Copy), etc can also be included.

To embed the mailto function in the webpage:

  1. Creating the mailto attribute:

Create a mailto attribute inside an anchor tag. Place this inside the body tags of the webpage.

Send Feedback

This will create a link that will open the email client, that will have the address field filled with the email address (in our case it is abc@abcmail.com)

2) Entering the subject in the subject field:

Moving on to the next step, we’ll add the subject in the subject field.

Send your Feedback

Enter the ‘subject’ keyword followed by the ‘?’ symbol. The ‘?’ symbol separates the email address from other information. The subject keyword is followed by a ‘=’ (equals to) operator after which the subject is entered.

3) Entering Information in the Body, Cc, Bcc Fields:

Once the subject is entered, information for other fields like body, Cc and Bcc are entered with their appropriate keywords preceded by a ‘&’.

&body=I am the body of the email that you are sending as a feedback

&cc=abcd@abc.com

&bcc=abcde@abc.com

Send your feedback.

Quick Guide to Understand the Code:

Text to be displayed on the webpage.

HTML MailTo Command: Complete Code

HTML mailto Attribute

Send your feedback.

Pitfalls:

There are some pitfalls that should not be overlooked before using the mailto attribute in a webpage.

  1. The developer should be aware that the visitor might not using an email client.

  2. At times the browser might not be able to identify the email client.

  3. Characters like " < > % in the mailto attribute might cause problems.

  4. It is recommended to use forms instead of the mailto attribute, as the mailto attribute may help in spreading harmful scripts like the melissa and love-bug worms that enter other machines easily and spread themselves over a network.