📅  最后修改于: 2023-12-03 14:41:46.676000             🧑  作者: Mango
The HTML mailto
attribute is used to create a hyperlink that triggers the user's default email client to compose a new email to a specified email address. This attribute can be added to any HTML element that supports the href
attribute.
The mailto
attribute is a simple yet effective way to make it easier for users to send emails directly from your web page. It eliminates the need for manually copying the email address and switching to another application to send an email.
The basic syntax for using the mailto
attribute is as follows:
<a href="mailto:email@example.com">Email me</a>
In this example, clicking the "Email me" link will open the user's default email client with a new email draft addressed to email@example.com
.
The mailto
attribute supports several additional options to customize the email further. These options can be specified by appending query parameters to the email address.
To specify the subject of the email, use the subject
query parameter:
<a href="mailto:email@example.com?subject=Hello%20World">Email me</a>
In this example, the email client will open with a subject line pre-filled with "Hello World".
To add a default message body to the email, use the body
query parameter:
<a href="mailto:email@example.com?body=Hi,%20I%20would%20like%20to%20contact%20you%20regarding%20your%20website.">Email me</a>
In this example, the email client will open with a default message body containing the specified text.
To send the email to multiple recipients, separate their email addresses with a comma:
<a href="mailto:email1@example.com,email2@example.com">Email us</a>
In this example, clicking the "Email us" link will open the email client with both email addresses in the recipient field.
Here is an example of how to use the mailto
attribute in HTML:
```html
<a href="mailto:email@example.com?subject=Hello%20World&body=Hi,%20I%20would%20like%20to%20contact%20you%20regarding%20your%20website.">Email me</a>
Remember to properly encode special characters in the query parameters and replace spaces with %20
in the URL.
Using the mailto
attribute is a convenient way to encourage users to contact you directly via email without having to navigate through multiple steps.
Note: Ensure that the user has an email client set up on their device for the mailto
attribute to function correctly.