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?
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="" />
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 script will be on your server, and, when called, it will :
iddifferent for each e-mail.
tracker.php script knows from which IP address it's been called -- like any other PHP script :
$ipAddress = $_SERVER['REMOTE_ADDR'];
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
As you know that
id=123456 corresponds to one specific email address, this allows to find out where each one of your subscribers are.