Email Tracking

From Koset

Jump to: navigation, search

How to track when/if someone reads your email. source

This is the code for your outgoing email.

<img src="http://my.website.com/1px_email_track.php?id=your@friend.com" />

This is the php code 1px_email_track.php that gets executed on your web server. It returns a 1 pixel gif file so it looks invisible to your recipient. This will produce a mysql record.

if( $_GET['id']!= '' )
{
$q = "UPDATE `email_tracker` SET `opened_dt` = NOW() WHERE `id` = ".sq( $_GET['id'] )." AND `opened_dt` IS NULL";
mysql_query( $q );
}
header( 'Content-Type: image/gif' );
header( 'Content-Length: '.filesize( '1px.gif' ) );
readfile( '1px.gif' );

You can also have the code email you back. Cool indeed.

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "localhost";
$mail->From = "verify@mysite.com";
$mail->FromName = "Verifier";
$mail->AddAddress("myself@mysite.com");
$mail->WordWrap = 50;
$mail->IsHTML(true);

$mail->Subject = "Email read verification.";
$mail->Body    = $_GET['id'];
$mail->AltBody = $_GET['id'];

if(!$mail->Send())
{
   echo ",";
   exit;
}

echo ".";
?>

It requires phpmailer Warning, it will email you every time the message is read (unless you add code to stop after the first time).

Personal tools