PHP电子邮件追踪系统
由于自己最近正在找工作,发求职信和简历时想知道对方是否已经看过自己的求职信。后来找到了www.spypig.com,它可以在收信人每次查看你的邮件时发送Email通知你邮件已经被查看过了,并记录查看的次数。使用过程中发现,它的实现原理还很简单,所以就用PHP照着葫芦画瓢自己写了个。
概述
当你想知道自己发送的邮件是否被收信人查看过时,使用电子邮件追踪系统(Email Tracking System)就可以帮助你。
使用方法
打开链接电子邮件追踪系统,输入Email地址和标题,选择接收通知的次数,然后激活获取Tracking Image,在一分钟内将其复制到你的Email邮件正文中,再正常发送邮件就行了。
实现原理
由于标签的src属性会主动引入外部文件,所以将调用“tracker程序”(此程序会正常输出一张图片)的URL作为src的值,并将此
放入邮件正文中与之一起发送出去。这样,每当收信人打开该邮件显示该
时,都会调用“tracker程序”,这时“tracker程序”会发送email通知你。而邮件也必须是HTML格式的才行。
程序说明
程序共有四部分:
- index.html -- 创建一个Email Tracker的程序界面,需要传递三个参数 - 邮件地址,标题和接收通知的次数。
- tracker.php -- 接收参数产生一个Email Tracker。
- blank.php -- 发送Email通知用户邮件已阅,并生成一个图片。
- msg_template.html -- 通知正文的模板。
代码
创建表的SQL:


tracker.php接收参数产生一个新的Email Tracker:


$db = get_db();
$ip = $_SERVER['REMOTE_ADDR']?$_SERVER['REMOTE_ADDR']:'127.0.0.1'; //获取用户IP
$unique_id = get_unique_id($ip); // 产生一个唯一ID
$number = intval($_POST['number']);
$email = trim($_POST['email']);
$title = trim($_POST['title']);
$sent_time = time(); // 作为发送邮件的时间
$db->query("INSERT INTO `email_tracker` (unique_id, email, title, number, ip, sent_time) VALUES ('$unique_id', '$email', '$title', $number, '$ip', '$sent_time')");
用于产生唯一ID的get_unique_id函数:


blank.php由邮件正文中Tracking Image调用,发送Email通知用户邮件已阅,并生成一个图片。


if(!($unique_id = trim($_SERVER['QUERY_STRING']))) exit_with_image_blank();
$db = get_db();
$tracker = $db->fetch_one("SELECT * FROM `email_tracker` WHERE unique_id='$unique_id'");
// 记录不存在,或Tracking已经结束
if(empty($tracker) && $tracker['times'] >= $tracker['number']) {
// 输出一个空白图片并退出
exit_with_image_blank();
}
// 邮件发送时到现在经过的时间
$time_elapsed = time() - $tracker['sent_time'];
// 不到一分钟
if($time_elapsed 60) {
if($tracker['times'] 0) { // 还未激活Email Tracker
$db->query("UPDATE `email_tracker` SET times=0 WHERE unique_id='$unique_id'");
}
exit_with_image_blank();
}
// 一分钟之后,times
if($tracker['times'] 0) {
$one_minute_ago = time() - 60;
// 删除所有经过一分钟还未激活的Email Tracker
$db->query("DELETE FROM `email_tracker` WHERE times $one_minute_ago");//unique_id='$unique_id'
exit_with_image_blank();
}
// 获取收信人IP
$rcpt_ip = $_SERVER['REMOTE_ADDR']?$_SERVER['REMOTE_ADDR']:'127.0.0.1';
if($rcpt_ip == $tracker['ip']) {
//与用户IP相同,也许是用户自己打开了Email
$tracker['times']++;
} else {
// 是收信人打开了Email, 查阅次数增加一次
$tracker['times']++;
}
$db->query("UPDATE `email_tracker` SET times=$tracker[times] WHERE unique_id='$unique_id'");
if($tracker['times'] >= $tracker['number']) {
// Tracking已经结束, 删除记录
$db->query("DELETE FROM `email_tracker` WHERE unique_id='$unique_id'");
}
// 发送Email
send_mail('mailtracker0@gmail.com', $tracker['email'], array(
'subject' =>'Your email "'.$tracker['title'].'" has been read!',
'body' =>notify_content($tracker, $rcpt_ip, $time_elapsed),
'headers' =>"MIME-Version: 1.0;\r\nContent-type:text/html; charset=\"utf-8\";\r\n",
'host' =>'smtp.gmail.com',
'ssl' =>true,
'port' =>465,
'auth' =>true,
'user' =>'mailtracker0',
'pass' =>'**********'
));
// 输出一个空白图片并退出
exit_with_image_blank();
send_mail函数用于发送通知邮件:



Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.
