How to insert a mail link in html
To insert a mail link in HTML, you can use the <a>
tag with the mailto:
protocol. Here's the basic syntax:
<a href="mailto:[email protected]">Send email to [email protected]</a>
Replace [email protected]
with the actual email address you want to link to.
Here are some additional options you can use:
subject
: sets the subject of the emailbody
: sets the body of the emailcc
: sets the CC recipientsbcc
: sets the BCC recipients
Here's an example with some of these options:
<a href="mailto:[email protected]?subject=Hello&body=Hello%20world&[email protected]">Send email to [email protected]</a>
This will open the default email client with the subject "Hello", body "Hello world", and CC "[email protected]".
Note:
- The
mailto:
protocol is not supported in all browsers, especially mobile devices. - Some email clients may not support all the options (e.g.
subject
,body
,cc
,bcc
). - You can also use a JavaScript library like jQuery to create a mail link with more advanced features.
Here's an example using jQuery:
<a id="mail-link">Send email to [email protected]</a>
<script>
$(document).ready(function() {
var mailLink = $('#mail-link');
mailLink.attr('href', 'mailto:[email protected]?subject=Hello&body=Hello%20world&[email protected]');
});
</script>
This will create a mail link with the same options as the previous example, but using jQuery to set the href
attribute.