// Tutorials //

How to create your own email pixel tracking in PHP

by Dillon - Updated -


When creating email campaigns, it’s important to know how many recipients actually opened your email. This information can help you determine if your efforts are working or if its time to change your strategy. Most mail champaign tools such as Mailchimp and SendInBlue use a technique called Pixel Tracking. In this post, you will learn how to create email pixel tracking in PHP and how to count the number of times your email was opened.

Note: This method requires the recipient to have downloaded images on the email.

Create the pixel for email tracking

First, you will need to create a PHP file or function which executes the following script. If you are using a function to run the script, you will need to ensure it is called when your specified endpoint is loaded. Example or

$pixel = imagecreate(1,1);

Next, set the color of the pixel which is going to be tracked. Ensure the color doesn’t stand out in you emails design. If the background of your email is white, then set the color to white using RGB values.

$color = imagecolorallocate($pixel,255,255,255);

Now it’s time to set the pixel to the color you chose as well as the image file type and headers.


Finally, destroy the image to free up memory.


Now following your URL, an image will be create 1 pixel by 1 pixel in your specified color. Use the URL as the image source in your email template.

<img src="">

Email Pixel Tracking in PHP

How to count email pixel tracking

To count up how many times this image was requested in emails, you can either use your server access logs or store a record in a database at the same time the pixel is created.

You can also use URL parameters to differentiate requests, such as a campaign id ( so you know which campaign the request was coming from.


You have now successfully generated an image in PHP for use in your email templates for tracking email opens.


Related Posts

Dillon Smart

👋 Hey, I'm Dillon!

I'm a Full Stack developer from the U.K. I've been building websites and applications for 11 years! Along the way I've picked up a few things, and share them here on

Feel free to reach out on Twitter!

0 Comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.