Defining a Default Subject in Mailto Links

Plastic building blocks making an email shadow
yangleephoto / Multi-bits / Getty Images

The mailto: HTML tag lets you provide visitors to your site with an easy way to contact you: email. Find out how to define a default Subject: line that will automatically appear when somebody clicks the mailto: link.

Feedback via Email

You may have a website. Be it a personal page, a site about your hobby or a commercial one, you do want your visitors to have a way to contact you, right?

Fortunately, HTML includes the mailto: tag that makes it easy to for website visitors to send you an email by just clicking a link.

Subjects

Let us now make the assumption that we do get quite a bit of email (a safe assumption). Some of it seems to be related to our website, somebody apparently sent it using that witty mailto: link.

Unfortunately, these messages often come without any subject line — it was just sent to a site on the web, anyway —, or they have obscure subjects — "Link", "photo" or, so that you cannot resist, "Can you help?". Maybe we can do something about this confusing situation.

Suggesting a Subject

We can.

Thankfully, those who created the mailto: tag also thought of a way to specify a default subject for the message created. It is not difficult to do at all.

Let us suppose we simply want to know that a message was sent via the mailto: tag, we strive to know that it somehow relates to our website. All we need is a default subject line of "Website Extraordinaire."

Line 9 of our example read:

…non licet <a href="mailto:bos@example.com”>bos@example.com

Up to this point, everything stays the same. But now we insert some code that will make our subject wish come true:

?subject=Website Extraordinaire

The question mark indicates that what follows is one or more arguments to the "target" of the link. In this case, the target is the email address we want the email to go. The argument is the suggested subject of the message.

Since there can be more than one argument, we first need to specify what we want to specify. This is done by "subject." Following a sign of equality comes the text of our subject: "=Website Extraordinaire."

That is all there is to it, you can type just about anything as the subject. Have a try for yourself.

Summary

To specify a default subject line for a mailto: link, the email address is followed by "?subject=" and then the text of your subject. Everything else stays the same and in place.