Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop Gmail from stripping the values out of URLs?

Tags:

html

email

gmail

I recently learned that webmail clients like Gmail will do alterations on HTML emails, for example adding target="_blank" to <a> tags.

I've also discovered that other alterations happen as well. When I send an HTML email to Gmail (and possibly other web mail clients) from my PHP script, variable values included in the URL of any links are being stripped out. So, for example, this is the value I'm setting in my PHP code:

$mailContent = '<p><a target="_blank" href="https://example.com/confirmation.html?verification=x1x1x1x1x1x1x1x&[email protected]">click here to go to the web site and activate your account!</a></p>';

But when the email is received in Gmail, the HTML code comes out like this:

<p><a target="_blank" href="https://example.com/confirmation.html?verification=&email=">click here to go to the web site and activate your account!</a></p>

The values x1x1x1x1x1x1x1x and [email protected] have been stripped out from within the <a> tag.

How do I protect the values of the variables that I want to pass to the URL so that Gmail won't remove them?

like image 808
Questioner Avatar asked Mar 27 '13 18:03

Questioner


People also ask

Does Gmail block emails with links?

But just because the links are from your own domain doesn't mean Gmail will not mark it as suspicious. Remember that links in the email body can be a cause of email blocking. Gmail may mark an email as spam because if it believes the link is not trustworthy.

What is data Saferedirecturl?

The data-saferedirecturl tag is added automatically. So the href shows the link that you will be clicking in the bottom of your browser but sends you to a google-originated URL like https://www.google.com/url?hl=en-GB&site.com/324dd3 . This way the third party don't have access to sensitive data.

How do I stop Gmail from opening links?

In Gmail go to settings --) General, and uncheck the option to open links in gmail.


2 Answers

Click View original/source on the message in Gmail to see if the URLs looks like they should then. If so you know that the problem is how Gmail is formatting the message for your viewing. If it's mutilated even in the source I was wondering if there's anything in your webpage/php/CMS (do you use one) that changes the code.

You should try URL-encoding as @Crisp said. Here's the W3 reference.

like image 178
PetaspeedBeaver Avatar answered Sep 23 '22 16:09

PetaspeedBeaver


Emailing in html uses Quoted-printable Encoding. The problem with your $mailContent is that the "=" must be represented by =3D

Try adding this: $mailContent = quoted_printable_encode($mailContent);

like image 24
CoolPal.Manila Avatar answered Sep 24 '22 16:09

CoolPal.Manila