Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to escape a string for a mailto link

Tags:

I've got a mailto: link in a page here including subject= and body= parameters but I'm not sure on how to correctly escape the data in the parameters.

The page is encoded in utf-8 so I guess all special chars like German umlauts should be encoded into utf-8 representations for the URL too?

At the moment I'm using rawurlencode() as urlencode() would insert + characters in all locations where spaces should have been but I'm unsure if this is the correct way to do so.

like image 667
bardiir Avatar asked Jan 20 '12 11:01

bardiir


People also ask

How do you insert a link into mailto?

On the Insert tab, click Link or Hyperlink. Under Link to, click E-mail Address. Either type the email address that you want in the E-mail address box, or select an email address in the Recently used e-mail addresses list. If you want to change the link text, in the Text to display box, type the text.

Are mailto links a good idea?

Essentially, an HTML mailto link is a link that triggers the user's default mail client to open so they can reply to a message. If you're a fan of email HTML forms and know your way around the coding aspect of things, a mailto link can be preferable, in some cases.


1 Answers

You just need to rawurlencode() the link at the end of the email address according the the W3C standards.

There is an example on the PHP Manual for urlencode (search for mailto on that page): http://php.net/manual/en/function.urlencode.php

like image 152
Paul Bain Avatar answered Sep 30 '22 19:09

Paul Bain