How to pass an URL in mailto's body

33,224

Solution 1

You need to encode the URL. This URL Decoder/Encoder tool will do the trick. The following seems to work:

<a href="mailto:[email protected]?body=Link goes here http%3A%2F%2Fwww.example.com%2Ffoo.php%3Fthis%3Da%26join%3Dabc%26user454
">Link text goes here</a>

Solution 2

I would URL encode the link you are using, so it would be:

<a href="mailto:[email protected]?body=Link%20goes%20here%20http%3A%2F%2Fwww.example.com%2Ffoo.php%3Fthis%3Da%26join%3Dabc%26user454">Link text goes here</a>

Solution 3

You can type javascript:alert(escape("YOUR URL")); in the address box of a browser and get the URL made safe for a mailto link. For example, type the following inside the address box of a browser and press Enter.

javascript:alert(escape("http://www.example.com/foo.php?this=a"));

You will get a message box that will display.

http%3A//www.example.com/foo.php%3Fthis%3Da

Opera and Mozilla-based browsers allow you to copy the displayed content from the alert box.

You could improve it by typing

javascript:alert("mailto:[email protected]?subject=My Subject&body="+escape("http://www.example.com/foo.php?this=a"));

so that you get the subject and body included in the link. Other improvements could be using a From name and line breaks using %0a.

javascript:alert("mailto:Just Me <[email protected]>?subject=My Subject&body=This is the link:%250a"+escape("http://www.example.com/foo.php?this=a"));

Solution 4

as I see you are using php then you can use "urlencode()" function

<a href="mailto:[email protected]?body=Link goes here <?php echo urlencode('http://www.example.com/foo.php?this=a&amp;really=long&amp;url=with&amp;lots=and&amp;lots=and&amp;lots=of&prameters=on_it
');?>">Link text goes here</a>
Share:
33,224
Simer Twilio Toronto developer
Author by

Simer Twilio Toronto developer

Toronto based Twilio developer / freelancer providing services to whole Canada and US clients. Working in Eastern timezone. contact at simer169 at gmail.com Expert in Twilio SMS, voice can help in Nexmo, Plivo, Telnyx, Stripe APIs too

Updated on August 25, 2020

Comments

  • Simer Twilio Toronto developer
    Simer Twilio Toronto developer over 3 years

    I need to send an URL of my site in the body so the mail recipient can click on that to join my site.

    However currently mail client renders the mail like this:

    Link goes here http://www.example.com/foo.php?this=a

    The URL is truncated on the & symbol, thus the whole process of joining failed. How can I pass the URL like http://www.example.com/foo.php?this=a&join=abc&user454 in mailto body?

    My current HTML is the following:

    <a href="mailto:[email protected]?body=Link goes here http://www.example.com/foo.php?this=a&amp;really=long&amp;url=with&amp;lots=and&amp;lots=and&amp;lots=of&prameters=on_it
    ">Link text goes here</a>
    
  • tekknolagi
    tekknolagi over 13 years
    i just tried it. it works! just instead used the first link he gave, not the second.
  • Simer Twilio Toronto developer
    Simer Twilio Toronto developer over 13 years
    it will solve any problem related to url so i marked it as correct answer.
  • yngrdyn
    yngrdyn over 8 years
    thank you for the escape function! This is what I was looking for