PHP 跟踪邮件和链接点击



我正在尝试跟踪是否有人(而不是谁)打开了我通过PHP脚本发送的邮件并点击了我嵌入在邮件中的链接。

在邮件中准备变量:

使用将在记录中加载的图像进行邮件点击跟踪.php:

<img src="http://localhost:8090/post_ch/admin/record.php?read=1" alt="Tracker">

链接点击跟踪:

<a href="http://localhost:8090/post_ch/portal/indexbab9.php?click=1">Link</a>

在数据库中插入记录

记录.php对于邮件点击记录:

<?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();
?>

对于链接点击:

<?php
if(isset($_GET['click']))
{
    $pdo = new PDO('SECURE (should work)');
    $statement = $pdo->prepare("INSERT INTO employee_clickedlink (clickedlink) VALUES (1)");
}
?>

如您所见,我只想在每次有人加载图像并单击邮件中的链接时将值"1"插入表中。有人知道问题吗?

对于每个prepare()语句,您需要调用execute()才能实际执行针对数据库的查询。

最新更新