X

Ampersand(&) and Question Mark (?) in mailto’s subject/body

“mailto” is used for email link in website but when we pass “&” or “?” in subject or body parameter then it ignores data after tag.

Read about mailto : mailto : Create e-mail link in website

See below example.

<a href="”mailto:someone@example.com?subject=This">Send email</a>

In above case, clicking on Send email link will open new mail window but it will show only “This is chetan, sabin ” in subject of mail as browser will consider & as parameter seperator.

To avoid this problem, you should use “%26” instead of “&”. You can use str_replace function for this in php.

Now, above example will be look like this which will work as you need.

<a href=”mailto:someone@example.com?subject=This is chetan, sabin %26 sujeesh&body=body line comes here”>Send email</a>

For Question Mark “?”, you can use “%3F”.

For php, it would be good practice if you use urlencode function to encode subject and body text.

This post was last modified on July 18, 2011 10:43 am

Categories: How To
Chetan Patel: Chetan Patel is blogger, writes on Tech News, current trends, Gadgets Reviews, Website owner guide and Tips. You can connect him at <a href="https://plus.google.com/118385579556796801405?rel=author">Google+</a> & <a href="https://www.facebook.com/patecj">Facebook</a>.