Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail App Stripping Out Equals Sign in Mailto Body

I am attempting to create a mailto link which populates the body of the email with the current URL. The problem I am having, is that the gmail android app strips out equals signs, including %3D

Here is the code I am using.

$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$currentUrl = str_replace('&', '%26', $currentUrl);
$currentUrl = str_replace('=', '%3D', $currentUrl);

<a href='mailto:?subject=".$emailsubject."&body=".$currentUrl."' class='actions'>Click to Send</a>

Example Href

<a href='mailto:?subject=12/12/2019 2L36 Brighton to Lewes&body=https://live.rail-record.co.uk/train/?c%3DW26711%26d%3D12/12/2019' class='actions'>Create Email</a>

On desktop, it works fine. On mobile, the query strings get cut off and the equals signs do not get included in the email body.

Would anyone be able to assist please, as to how to get the equals into gmail app? Thanks.

An example of the mailto body would contain a link like this: https://live.rail-record.co.uk/train/?c=H17216&d=11/12/2019 The URL inserted into the email body however, is cut off after ?c - the first equals sign. Works fine in desktop mail apps but doesnt work on gmail android. Regarding the above link, there is a bit at the bottom that says "Create Email" you can click that to test it.

like image 576
trainmania100 Avatar asked Dec 12 '19 13:12

trainmania100


1 Answers

In Android URL encoding is not enough, you need to double encode the URL and it will work fine (tied it out myself).

Here you can see how to do it in js: How to double encodeURIComponent in javascript?

like image 124
Androidz Avatar answered Nov 06 '22 07:11

Androidz