Defining a Default Subject in Mailto Links

William Powell & Sons - Gun & Rifle Makers - Carrs Lane - ACME
You pick the default subject. © Elliott Brown; CC BY 2.0 license

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 have a web site, do you not? 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—do you not?

Fortunately, HTML includes the mailto: tag that makes it easy to for Web site 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, I gather). Some of it seems to be related to our web site, 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.

Do you still remember the example from part one?

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 Web site.

All we need is a default subject line of "Web Site 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=Web Site 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 (more about that later), 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: "=Web Site Extraordinaire.

That is all there is to it, you can type just about anything as the subject. Have a try, play a bit with that feature while I try to sum up what we have learned…

Mailto: Default Subjects: 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.

(Updated November 2015)

Was this page helpful?