I'm trying to track whether someone (not who) opened the mail I sent via PHP script and clicked on a link I embedded in the mail.
Prepare variables in the mail:
mail-click tracking with an image which will be loaded in record.php:
<img src="http://localhost:8090/post_ch/admin/record.php?read=1" alt="Tracker">
link-click tracking:
<a href="http://localhost:8090/post_ch/portal/indexbab9.php?click=1">Link</a>
Insert records in DB
record.php for mail-click records:
<?php
// (inside "record.php")
header('Content-Type: image/gif');
if(isset($_GET['read']))
{
$pdo = new PDO('SECURE (should work)');
$statement = $pdo->prepare("INSERT INTO employee_clickedmail (clickedmail) VALUES (1)");
}
//push out image
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Disposition: attachment; filename="blank.gif"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize('blank.gif')); // provide file size
readfile('blank.gif'); // push it out
exit();
?>
AND for link-clicks:
<?php
if(isset($_GET['click']))
{
$pdo = new PDO('SECURE (should work)');
$statement = $pdo->prepare("INSERT INTO employee_clickedlink (clickedlink) VALUES (1)");
}
?>
As you can see I simply want to insert the value "1" into the tables everytime someone loads the images and clicks the link in the mail. Anyone knows the problem?
For each prepare()
statement, you need to call execute()
in order to actually execute the query against the database.