Anyone who has experience in web development must have used the mailto function in HTML at some point of time. Mailto syntax is quite simple & it creates a hyperlink in an HTML file. Clicking on this hyperlink will launch the default mailing app on your system, either PC or phone. For example, if your default mail app is the Office Outlook, it will directly open that app upon clicking the link.
Also Read: How To Manage Email Using Mobile
Most people use mailto function only to link a single email address, but it provides more features which are quite powerful but are rarely used. The best part is that these are extremely easy to use as well, so you won’t need to invest a lot of time to learn these useful features.
1. Normal mailto syntax
This is the normal syntax of mailto –
<a href=” mailto:test@gmail.com”>Link</a>.
This will launch the mail with the recipient’s email set as “test1@gmail.com”. Note that you can send only one email using this syntax.
2. Adding subject
You can also set the subject of the email. You need to follow the syntax below to achieve this –
<a href=”mailto:test@gmail.com?subject=email%20subject”>Link</a>
Note that we have used %20 in between email and subject. Remember that %20 needs to be added wherever you want a space character and if you want the newline character, you should use %0A.
3. Adding cc and bcc
The mailto syntax allows you to add the cc and bcc recipients.
<a href=”mailto:test1@gmail.com?cc=test2@gmail.com&bcc=test3@gmail.com “> Link</a>
This syntax will add “test2@gmail.com” to cc field and “test3@gmail.com” to the bcc field of the email.
4. Sending email to multiple persons
This is one of the most important features of mailto. It’s really surprising that many developers have no idea about this feature of mailto.
Often, it is seen that developers use separate mailto link for each email address to send the same message. That is completely unnecessary since mailto allows you to set several email address in one link. This is the syntax –
<a href=” mailto:test1@gmail.com,test2@gmail.com”>Link</a>.
You can add more email addresses; remember that each email address needs to be separated by a comma.
Also Read: Work Task Automation Guide to save you Time
5. Adding message
Finally, you can also add a message using mailto. Simply follow the syntax below –
<a href=”mailto:test@gmail.com?body=message%0Ain%0Anew%20line”>Link</a>
Set the message you want in the body, and it will appear in that mail app. Also, notice how the %0A and %20 have been used to add new lines and spaces respectively.
This guide clearly explains how powerful the mailto syntax is. Next time, keep these points in mind, and these will definitely help you a lot in web development.