Written by Cody Snider
Saturday, July 24th, 2010
It’s a little rude to ask someone to confirm they read an email, isn’t it? Well, there’s a way to get a confirmation without them knowing it using PHP and htaccess.
First, create a directory in your images folder called ‘email’ (/images/email/ for this tutorial). Inside that folder, create an .htaccess file. Be sure that your Apache directive for AllowOverride is set to All.
In this .htaccess file, add the following:
View Code HTACCESS
RewriteEngine On ReWriteRule ^image(.*?)\-\d{4}\.png$ track.php?x=$1 [L]
Next, create a 1x1px PNG image in the same folder and name it track.png. This will be the image loaded in the email.
Finally, in the same folder create a file named track.php and add the following:
View Code PHP
<?php $trackingNumber = $_REQUEST['x']; // logic here for updating your database tables header('Content-Type:image/png'); echo file_get_contents('track.png'); ?>
Inside the email you are sending, include the following line. This will allow the system to track the ID ’1234′ when that image is loaded. Additionally, as we are using htaccess to mask the script being used, the image will appear to be a regular PNG without any extra parameters.
View Code HTML
<img src="http://www.yoursite.com/images/email/image1234.png" />
In part 2 of this tutorial, we’ll discuss where the ID is generated and how it is used.