Search code examples
javahtmlspringescapingmailto

Escape & symbol in MailTo


I have a URL like this: http://localhost:9001/view/shopindex/display?keyword=test&searchPostcode=Postcode and I'm putting it in the body of a new email message using HTML mailTo (I know that there are better options to mailTo but I'm restricted to this). Effectively I have this:

<a href="mailto: ?subject=Look at this link&amp;body=http://localhost:9001/view/shopindex/display?keyword=test&amp;searchPostcode=Postcode"></a>

The problem is that when I click and I get the new e-mail message opened, I get only the following in the body:

http://localhost:9001/view/shopindex/display?keyword=test

I think the mailto is identifying the & symbol in the query string of the web page URL as part of the mailto URL. Is there a way I can escape it?

Thanks!

Krt_Malta


Solution

  • Try URL-encoding the ampersand character instead:

    http://localhost:9001/view/shopindex/display?keyword=test%26searchPostcode=Postcode
    

    It works fine for me in Firefox, you can test it here.