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

拟墨画扇 提交于 2019-12-13 12:00:16

问题


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=yyyy@email.com">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 yyyy@email.com 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?


回答1:


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.




回答2:


This may not be the perfect answer, but if your application allows for it, I have used URL shorteners a number of times.

http://goo.gl/ is my preferred because the API is super easy to implement and google is very fast. I have a function in a class and I just run my url through it and send the return wherever I need it to be.




回答3:


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);



来源:https://stackoverflow.com/questions/15666796/how-do-i-stop-gmail-from-stripping-the-values-out-of-urls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!