You will need to create an image that you're going to use in the newsletter. Most often a 1x1 pixel image will do the job. Don't use a background image though as this won't always get through.
You'll need to change or create an .htaccess file. in the directory where the image is. I use something like this
RewriteEngine On
RewriteRule ^(.*).jpg image.php?$0 [L]
Now for image.php
<?php
$var_utmac='UA-XXXXXXXX-1'; //enter the new urchin code
$var_utmhn='yourdomain.com'; //enter your domain
$var_utmn=rand(1000000000,9999999999); //random request number
$var_cookie=rand(10000000,99999999); //random cookie number
$var_random=rand(1000000000,2147483647); //number under 2147483647
$var_today=time(); //today
$var_referer=$_SERVER['HTTP_REFERER']; //referer url
$var_utmcsr='ContactManager'; // the campaign source
$var_utmcmd='email'; // the campaign medium
$var_utmccn=$_SERVER['argv'][0]; // the campaign name
$var_uservar='-'; //enter your own user defined variable
$var_utmp='tracker/'.$_GET['url'].'.'.$_GET['filetype']; //this example adds a fake file request to the (fake) tracker directory (the image/pdf filename).
$urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='.$var_utmhn.'&utmr='.$var_referer.'&utmp='.$var_utmp.'&utmac='.$var_utmac.'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.$var_today.'.'.$var_today.'.'.$var_today.'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.'.2.2.utmccn%3D('.$var_utmccn.')%7Cutmcsr%3D('.$var_utmcsr.')%7Cutmcmd%3D('.$var_utmcmd.')%3B%2B__utmv%3D'.$var_cookie.'.'.$var_uservar.'%3B';
$handle = fopen ($urchinUrl, "r");
$test = fgets($handle);
fclose($handle);
$showit = $_GET['url'].'.'.$_GET['filetype']; //this is where the real file should be located
$filename = $_SERVER['argv'][0];
header('Content-Type: image/jpeg');
$imageurl = fopen($filename, "r"); //this is where the real file should be located
while (!feof ($imageurl))
{
$image = fgets($imageurl, 4096);
echo $image;
}
fclose($imageurl);
?>
Post Merge: March 12, 2010, 09:35:54 PM
Some servers, and one of my providers does this, don't allow you to fopen a URL, in which case the work around is to create a function at the top of the code as follows:
function get_content($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
and replace
$handle = fopen ($urchinUrl, "r");
$test = fgets($handle);
fclose($handle);
with
$test = get_content($urchinUrl);