If you require the ability to create an email link that, when clicked, will open a new email window (using the default email program) with the necessary fields pre-populated, such as To, CC, Bcc, Subject, and Body then you can use "mailto" feature.

We can pass many parameters like subject, body, to etc.,  to "mailto" URL scheme. When passed it will be automatically set and preloaded in the new email. Refer the example below:
<a href="mailto:someone@example.com?subject=Email from webdevelopmentscripts&body=This is the body content">Send email</a>

But when you have ampersand(&) or question mark (?) in the subject or in the body content, those text will be striped out. Look at the below example:
<a href="mailto:someone@example.com?subject=Email from webdevelopmentscripts & from author&body=This is the body content">Send email</a>

As per the above example, in the newly opened email you will see  "Email from webdevelopmentscripts & from author" instead of "Email from webdevelopmentscripts". This is because "&" will be considered as parameter separator and removed from the subject.

We should use "%26" in place of ampersand (&), similarly we should use "%3F" in place of question mark (?). The above example will look like below.


Allow ampersand (&) and question mark (?) in the mailto link

<a href="mailto:someone@example.com?subject=Email from webdevelopmentscripts %26 from author&body=This is the body content">Send email</a>



Comments (0)
Leave a Comment

loader Posting your comment...