跟踪像素和Gmail代理的问题

时间:2016-07-06 14:03:44

标签: php email proxy gmail event-tracking

我正在尝试为从wordpress发出的电子邮件实现自定义跟踪像素。

感谢这些帖子:

Tracking email with PHP and image

Tracking email opens with a real image

特别是

http://www.phpdevtips.com/2013/06/email-open-tracking-with-php-and-mysql/

我能够实现核心理念。

电子邮件通过加载跟踪像素         <img src="https://www.example.com/tracking.php?order_id=1" width="100" height="100" />

并在tracking.php中

$graphic_http =  'https://www.example.com/GIF-example.gif';

header('Content-Type: image/gif');
readfile( $graphic_http );

在浏览器中打开tracking.php文件会打开gif图像供下载。

然而,跟踪像素/跟踪图像未显示在Gmail电子邮件中。只有一个损坏的图像徽标,当我点击显示图像时,此链接已打开

https://ci5.googleusercontent.com/proxy/l2xUKFGnNFKm64zEYmJhOcUmEJm15w9MC1txRRF01tpKlcL3t3O16aMJgbYQkucBySV0xV2T0EsCwikOAC0Z4em6uPzSs38lkHrYBvosRRAk14EfPoEXqC5JdLxRm8ToZmGSQqt_RwHCaBE_3uLgQDVEB05Rdtkq-Xzuw30=s0-d-e1-ft#https://www.example.com/tracking.php?order_id=1

表示Google 404:

Google 404.那是一个错误。

所请求的URL /代理/ l2xUKFGnNFKm64zEYmJhOcUmEJm15w9MC1txRRF01tpKlcL3t3O16aMJgbYQkucBySV0xV2T0EsCwikOAC0Z4em6uPzSs38lkHrYBvosRRAk14EfPoEXqC5JdLxRm8ToZmGSQqt_RwHCaBE_3uLgQDVEB05Rdtkq-Xzuw30 = S0-d-E1-英尺未在此服务器上找到。我们知道的就这些。

Google的代理无法读取php脚本似乎是一个问题。 tracking.php和GIF-example.gif文件都有775个权限,可以公开访问。

在Hotmail上,这确实有效,因此Google Proxies似乎确实存在问题。

有人知道如何让Google Proxies访问此跟踪像素吗?

2 个答案:

答案 0 :(得分:3)

我找到了答案:问题在于Google Proxies和问号?在https://www.example.com/tracking.php?order_id=1

谷歌Proxies地址搞砸了,因为它已经有一个问号,结果是404.

我使用https://www.example.com/tracking.php/order_id=1解决了问题,然后在tracking.php上解决了问题,我没有使用$_GET$_SERVER['REQUEST_URI']并解析了/order_id=字符串。

跟踪像素显示在Gmail中,并在tracking.php脚本中进行跟踪。

答案 1 :(得分:0)

所有标题都试图强制浏览器下载文件并忽略它的文件类型(因为你从不说它是什么文件类型)。要在浏览器中显示图像,您需要设置正确的标题。

基本上你需要做的就是:

$orderId = isset($_GET['order_id']) ? $_GET['order_id'] : null;

if ($orderId) {
    // Save stuff in your DB or how you want to log it.
}

header('Content-Type: image/gif');
echo file_get_contents('/absolute/path/to/image.gif');
exit; // Not really necessary, but just to make sure there's no more output.