I am using
window.location.href = 'mailto:?body=visit http://example.com/?content=link';
window.location.href = 'mailto:?body=<?php echo $content; ?>';
rawurlencode function[php docs] to encode any characters in your input that aren't valid in URLs.
<?php $content = "Hello, this' an...\n\nexample!"; ?> window.location.href = "mailto:?body=<?php echo rawurlencode($content); ?>";
window.location.href = "mailto:?body=Hello%2C%20this%27%20an...%0A%0Aexample%21";
It is true that you normally would want to use
addslashes[php docs] when you're putting something in a quoted string. In this case it would have no effect because the output of
rawurlencode doesn't have any characters that need to be escaped with slashes.