John Davidson

php - Using a mailto link, how do I prevent Gmail from stripping the = sign and everything after it from the URL's query string?

0 comments
Message:


I am trying to format a mailto link that works with a variety of mail clients. This works with Mac's "Mail" and Thunderbird. However, when I click the link on my Android phone, the query string in the URL is stripped starting with the equals sign. I have tried to add code to specify the content type, to parse the query string and re-add it, etc. So far, nothing works. Here's my code:


<?php
ini_set('default_charset', 'UTF-8');
$BASEURL = strtok($_SERVER["REQUEST_URI"], '?');
echo '
<li><a href="mailto:?subject=An Article Worth Reading: ' . $ALTITLE . '&amp;body=I found this article worthwhile and think you will too:%0D%0A %0D%0A
https://worldviewpublications.org' . htmlspecialchars($_SERVER['HTTPS_HOST']) . $BASEURL . "?" . htmlspecialchars($_SERVER['QUERY_STRING']) . "%0D%0A";
echo '">share with a friend</a></li>
';
?>

I'm pretty proficient in html/css but a beginner with PHP, so I am not at all sure about the efficacy of some of the PHP I added. I'd greatly appreciate any help.



My Answer:
To prevent Gmail from stripping the = sign and everything after it from the URL in a mailto link, you can encode the URL using percent encoding. This will convert special characters like = into a format that can be safely included in the link.

Here is an example of how you can encode the URL in a mailto link:

html
Send Email


In this example, the URL `http://example.com/page?param=value` is encoded as `http%3A%2F%2Fexample.com%2Fpage%3Fparam%3Dvalue` to prevent Gmail from stripping the = sign and everything after it.

By encoding the URL in this way, you can ensure that the full URL is preserved in the mailto link when clicked in Gmail.

Rate this post

3 of 5 based on 9103 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us