使用 PHP 和图像跟踪电子邮件 [英] Tracking email with PHP and image
问题描述
我见过像 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
. - 做一些事情——比如记录email 123456 has been opening",以及一些额外的信息
- 返回一个小图片的内容;就像一个 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 地址开始,您可以使用地理定位服务来找出电子邮件是从世界上的哪个地方打开的.
举几个例子,你可以看看 MaxMind 或 IPInfoDB
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 和图像跟踪电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!