Determine if an Email is Read Using PHP (and Log Who Read It)

Most web based email software will permit you to determine if an email is read by including a small image into the body of the HTML message. When rendered into an email client a request is made for the image and the server-side fancy work logs the details into a database. The PHP code on this page is designed to emulate the feature just described in a very simple way.

The Result

Following is an example of logs that are recorded when a request for your image is made:

The last record was obtained by inserting the image into an outlook email; the others were accessed via a web browser. The image location is the URL of your PHP script; in my case,[custom_word]/reademail.jpg. Since I’ve used a simple .htaccess rewrite file in the same directory as my code, I’ve written the URL referencing the image (as a .jpg file) without the .php file extension. Without the rewrite you should use

The last field in the log example above is the custom field you can use to determine who it was that read an email ([custom_word] in the image URL). Most mass email clients permit you to include a custom field (name, email, id) into the email message and it’s intended that you’ll use one of those here.

The PHP Code

The following code should be copied into a file called reademail.php.

If you plan on rewriting your image URL so it has the .jpg extension you should also include the .htaccess file below. This is a preferred method since it assists the browser or email client in rendering the image as an image rather than gibberish text.


Upload the entire reademail folder to your webserver (includes reademail.php and .htaccess).

Access the script via[CustomField]/reademail.jpg. Note the log.txt file isn’t created until you first make a request for the image script.


To validate the ‘custom field’ input I’m using just alphanumeric text, hyphens, and underscores. We validate this in both the PHP script and the .htaccess file. If you choose to include other characters you’ll have to rewrite this. If you were to use an email it may be sensible to hash it so it includes only permitted characters (for example, MD5 will include only [a-fA-F0-9] characters)… or you could just validate the email!

To edit the HTML in MS Outlook I use outlookhtmleditor . Screenshot below.

Rather than just including a pixel-sized image in your email you might consider generating your email (image) signature in the manner described. In addition to logging the read email you can add additional features such as the ability to use specific full-featured image email signatures based on the recipient or your own sender address. You might also consider an action that’ll fire off an email ‘read receipt’. I’ve personally used the signature method to automatically generate different email signatures for specific (and known) recipients.

If you were to build this funky little function into an actual tool you use you would almost certainly want to store data in a database. The text file is prone to errors and it was only used for the purpose of the demonstration.

Download the Code

Download the PHP function reademail . Extract and upload the entire reademail folder.

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *