11/18/2024 | News release | Distributed by Public on 11/18/2024 06:11
Updated: November 18, 2024
Published: March 03, 2023
Want to learn how to add a mailto link in HTML? You've found the right blog post.
Mailto allows visitors on your site to quickly and easily send an email to any address you specify. You can even have the email auto-populate with CC and and BCC recipients, a subject line, and body text.
In this post, we'll tell you what you need to know to add mailto links to your website. Let's dive in.
In HTML, a mailto link is a kind of link that opens a new email in the default email client of the user's browser, instead of to another web page. A user can click a link and then quickly send an email from their own address to one or more recipients specified in the mailto link.
A free checklist to you help you stand out from the competition featuring Software Developer and YouTube Creator Tech With Tim.
All fields are required.
To create an HTML mailto link, you'll use the anchor () element, just as you would for any other hyperlink. For the anchor's href attribute parameter, you'll use the mailto: followed directly by the email address. Here's the syntax:
And here's an example of the link in action. (Note that, for the example below, I've also set the mailto link to open in a new tab to make the demonstration work properly. However, this is not necessary on a normal HTML web page.)
See the Pen html mailto by HubSpot (@hubspot) on CodePen.
When you click the mailto link above, your browser will open up a new email with your default email client. You'll also see that the email address you provided populates the "to" field.
You can also include add multiple recipients to your link by separating each email address with a comma:
See the Pen html mailto - multiple recipients by HubSpot (@hubspot) on CodePen.
You can also add additional parameters to your mailto link to make the user experience more seamless. A mailto link accepts the following parameters:
When adding optional parameters, always place the mailto parameter first, then follow the parameter with the ? delimiter character. Separate multiple optional parameters with the & character.
Here are some examples of mailto links with optional parameters:
See the Pen html mailto - parameters by HubSpot (@hubspot) on CodePen.
Unfortunately, since they have no built-in spam protection by default, mailto links are vulnerable to spam attacks. It's easy to build a bot that crawls your webpage looking for mailto links and then flooding them with spam.
That's why we recommend collecting emails from visitors via a form, rather than a simple mailto link on your page. With a form that sends email, you can add a captcha and other spam prevention features to limit the amount of unwelcome emails in your inbox.
Also, it should go without saying, but don't put an email address in your mailto link from someone who doesn't want to get a bunch of emails from your website!
A free checklist to you help you stand out from the competition featuring Software Developer and YouTube Creator Tech With Tim.
All fields are required.