Track email open with php

Hi

I have read on internet that the companies track email as “open” by inserting an transparent image.

But i am not able to found what actually they insert into the source code of that image that marks or updates in the database as “open”.

Do they insert an update query into the source code of image ??

Can please tell me a example with img src ??

Thanks
Vineet

There’s a reasonably comprehensive answer here: http://stackoverflow.com/questions/5448381/

Hi Droopsnoot

Normally to do query when the id is set in browser address bar

http://address.com/tracking.php?id=12345

and then in php we do query as

if(isset(id))
{
    do query
}

But i am not able to understand

How in the EMAIL CLIENT just simply writing

<img src=http://address.com/tracking.php?id=12345> 

will do the same thing (means we dont have to copy paste this link in browser).

Hope you are able to understand what i am trying to ask ??

Thanks
Vineet

It’s similar to how a normal img tag with a script would be used for something like a captcha image - the viewer (in this case the email client) connects to the server and runs the script, and your script returns some kind of image (often a small blank, but could be a company logo or whatever) which is displayed. In the background, though, it’s recorded that the user with that id has opened their email. Or previewed it.

Obviously if they have images disabled, or a number of other ways, it’s not going to work.

I did not set this in my email program but by default any emails with images have the images hidden to presumably stop you finding out if the email has been opened.
I would think this is to help prevent spammers knowing if the email address is a valid one.

So it is not a very efficient way to track emails.

Hi Droopsnoot

i would like to know how can i write query string with src=“logo.jpg”

<img src="logo.jpg?tracker.php?id=123456" alt="" width="1" height="1" border="0">

I have to add two “?” marks signs into the src url.

Is it fine or is there any other way ??

because if i replace first ? sign with slash / then image is not shown

<img src="logo.jpg/tracker.php?id=123456" alt="" width="1" height="1" border="0">

i even tried replacing first ? sign with & sign , then also the image is not displayed.

Image is displayed if two ? signs are added just like in first url

Thanks
Vineet

The php page will generate the image and so you only need:

<img src="tracker.php?id=123456" alt="" width="1" height="1" border="0">

Yes, have a look also at http://stackoverflow.com/questions/900207/return-a-php-page-as-an-image which covers it and links to the php manual for more information. Obviously before you return the image data you’d update your database too as that’s the point of calling the script. The idea is that instead of pointing the img tag to your jpg you point at the php script, which then must return the image data once it’s done whatever it needs to do.

And yes, as @rubble mentioned, if your clients have images disabled, then this won’t work very well.

Hi droopsnoot

I understand if the images are disabled then i will not get result.

But what i wanted to ask was
is it fine to have two “?” signs in the src of image ??

<img src="logo.jpg?tracker.php?id=123456" alt="" width="1" height="1" border="0">

I want to have this query on the original image , logo.jpg which should display in the email also.

thanks
vineet

Hi Rubble

You mean to say the “logo.jpg” will be displayed in the email through tracker.php even if i dont write logo.jpg in the src

i want to insert query on the original image logo.jpg which is actually display in the email

vineet

No, the correct way to have more than one $_GET variables is like
folder/logo.php?first=foo&second=bar&third=baz
the &s should be coded as &amp;s if you don’t want problems

Although there are ways to rewrite a request to a web server to do different things when you call for a resource (like an image file), it simply isn’t normal or usually a necessary practice to call on an image to make other things happen in the web server. It overcomplicates the server setup. If an image resource is called, an image should be served. The best practice to do such tracking through an image request is to simply request a php file and let PHP send out the image as the proper response, as has been suggested earlier in this thread.

Scott

There’s also another, potentially simpler way. I wrote about it here.

No hosting required, and no server setups needed : )

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.