使用php发送的邮件上的按钮点击计数器

时间:2018-03-08 06:24:47

标签: php email campaign-monitor click-counting

我正在使用php mail()发送邀请邮件。我想跟踪有多少人接受邀请并拒绝邀请。我使用两个按钮接受和拒绝。我该如何实现点击计数器?是否可以更新计数而不将页面从邮件重定向到我的网站?

1 个答案:

答案 0 :(得分:2)

在您的服务器上创建一个文件:counter 创建一个PHP文件,增加或减少counter文件中的数字。

上调:

$readf = fopen("counter", "r");             //open the file in read mode
$count = fread($readf,filesize("counter")); //read the content in it
fclose($readf);                             //close the file in read mode
$writef = fopen("counter", "w+");           //open the file in overwrite mode
$count++;                                   //increase the count by one
fwrite($writef, $count);                    //write changes to the file
fclose($writef);                            //close the file in overwriting mode

减少:

$readf = fopen("counter", "r");
$count = fread($readf,filesize("counter"));
fclose($readf);
$writef = fopen("counter", "w+");
$count--;
fwrite($writef, $count);
fclose($writef);

确保文件counter首先存在于计数0:

if(!filesize("count")){
$writef = fopen("counter", "w+");
    fwrite($writef, "0");
    fclose($writef);
}