5

I am trying to create a tracking pixel that will log the time an email is opened in my database. I am doing this by calling a php link in the URL path.

<img src="http://example.com/lp/index.php?p=tp&ord=xxxx" />

Then in my controller I have the code that logs the time followed by this bit of code that reads a 1x1 image and displays it to the screen.

$fileOut = 'inc/sections/common/tpixel.jpg';
header("Content-Type: image/jpg");
header('Content-Length: ' . filesize($fileOut));
readfile($fileOut);

This works as expected if the img tag is placed in the HTML of a web page and the web page is viewed in a browser. However when I place this image tag into an email and view it using gmail the timestamp does not fire nor does the image display. It just returns a 404 error.

Any ideas as to why viewing the image in gmail would return not found? Is this not the best way to do this? This is my first attempt at a tracking pixel.

Also please note I do click the show images in the email to activate it.

user3167249
  • 1,082
  • 2
  • 14
  • 28
  • 404 thats your server? so has the url been changed? –  Dec 30 '15 at 00:11
  • Why would you down vote this? It is a legitimate question and clearly defines the issue with the code to support the question. – user3167249 Dec 30 '15 at 00:12
  • Yes it's not able to find it on my server for some reason. For the image tag above yes I put a fake URL as per the guidelines for posting URL's on SO. However I noticed the actual image URL in gmail is: ttps://ci4.googleusercontent.com/proxy/nFwubQ7rKMx06k6-ke1fBzNhumlT7Iq7sHWZw4wkVIP0i8ZMKgE_2RUZEsayjgUeEiCdu7nfGKZxajkwxIFFBlBaMORJh3dbTvxOIC-3VJvR=s0-d-e1-ft# – user3167249 Dec 30 '15 at 00:46

1 Answers1

2

This will happen if your URL is not publicly accessible.

This is because GMail proxies images: https://blog.filippo.io/how-the-new-gmail-image-proxy-works-and-what-this-means-for-you/ -- so it is not enough that you can access that tracking pixel's URL from your browser: GMail's servers need to be able to access it, too.

jsalvata
  • 2,155
  • 15
  • 32
  • 1
    The same happens to me even if the URL of the tracking pixel is publicly accessible and has 775 rights. Gmail proxy doesn't seem to be able to catch it or whats the problem and how to solve it? – MrWeix Jul 06 '16 at 13:27