问题描述
我已经看到像spypig.com这样的服务,在电子邮件中放置一个小图像,并在打开时跟踪它。他们跟踪城市,国家,IP地址等。这是如何完成的?
I have seen the service like spypig.com placing a small image in the email and tracking when it is opened and from where. They track city, country, IP address etc. How is this done?
- 我们如何知道邮件何时打开?图形
如何生成? - 如何检测到IP地址,如何从
了解位置?
推荐答案
基本上,在电子邮件的HTML正文中,将有一个< img>
标签,如下所示:
Basically, in the HTML body of your email, there will be an <img>
tag that would look like this :
<img src="http://www.yoursite.com/tracker.php?id=123456" alt="" />
当有人读取邮件时,启用了图像,电子邮件客户端将向 tracker.php
,以加载图像,将其 id = 123456
作为参数。
When someone reads his mail, with images enabled, the email-client will send a request to tracker.php
, to load the image, passing it id=123456
as a parameter.
这个 tracker.php
脚本将在您的服务器上,当被调用时,它将:
This tracker.php
script will be on your server, and, when called, it will :
- 查看
id
参数 - 使用它找到它对应的电子邮件地址 - 当为每个订阅者生成电子邮件时,您将生成每个电子邮件的
id
。 > - 做一些东西,如日志电子邮件123456已经打开,另外一些附加信息
- 返回一个小图像像一个1x1透明的gif。
- Check the
id
parameter, - Use it to find to which email address it corresponds -- when generating the email for each one of your subscribers, you'll have generated an
id
different for each e-mail. - Do some stuff -- like log "email 123456 has been opened", and some additional informations
- return the content of a small image ; like a 1x1 transparent gif.
tracker.php
脚本知道从哪个IP地址被调用 - 像任何其他PHP脚本:
The tracker.php
script knows from which IP address it's been called -- like any other PHP script :
$ipAddress = $_SERVER['REMOTE_ADDR'];
从这个IP地址开始,您可以使用地理位置服务来查找世界的电子邮件已经打开。
作为几个例子,您可以查看或
And, starting from this IP address, you can use a geolocation service to find out from where in the world the email has been opened.
As a couple of examples, you could take a look at MaxMind, or IPInfoDB
如你所知, id = 123456
对应一个特定的电子邮件地址,这样可以找出您的每个订阅者的位置。
As you know that id=123456
corresponds to one specific email address, this allows to find out where each one of your subscribers are.
这篇关于跟踪电子邮件与PHP和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!