


After using phpmailer to send an email, many people want to know whether the other party has read the email? Generally speaking, we cannot know this, so is there any way?
There is a simple solution to this problem. We know that the email content can be sent in the form of html, and we can insert pictures into the content, so the key lies in the picture.
Suppose the content of our email is like this:
The file content.php code is as follows:
<table width="555" height="50" border="0" align="center" cellpadding="0" cellspacing="0" background="<?=$bg?>"> <tr> <td>这是测试内容</td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table>
How to write this $bg? What if the email is sent to multiple people? How to distinguish here?
Assume the link is like this: http://www.xxx.com/image.php?email=$email Look at the code of image.php again
The file image.php code is as follows:
<?php $email=$_GET["email"]; if($id) { include_once("/conn.php"); mysql_query("update mail_list set has_read='yes' where email='$email'"); } header("Content/type:image/gif"); $im=imagecreatefromgif("bg.gif"); imagegif($im); imagedestroy($im); ?>
You may understand after seeing this. So the content of the email I sent is like this:
<?php ob_start(); include_once("content.php"); $content=ob_get_contents(); ob_end_clean(); ?>
Written here, we have not replaced the background image in the email content. The next problem will be gradually solved. Question, this is part of the code for sending emails using phpmail:
<?php /* $contact=array("userA"=>"aaaa@sina.com","userB""=>"bbb@163.com","userC"=>"ccc@qq.com"); */ foreach ($contact as $unm=>$email) { $bg_file="http://{$_SERVER['SERVER_NAME']}/image.php?email=$email"; $str=str_replace('background=""',"background=\"$bg_file\"",$content); $mail->MsgHTML($str); $mail->AddAddress($email,$unm); $mail->Send(); } ?>
Why do we need to send them one by one in a loop here? Because in order to distinguish which contact has read the email, the background image of the content of each email is displayed differently. Before sending, we process the content and replace the background, so that the src of the background image of the email content we see becomes like this: http://www.domain.com/image.php? email=aaa@sina.cometc.
Note that there is another problem here. After you execute the above code, you will find a problem. There are 3 emails sent to the first person, 2 emails to the second person, and 1 to the third person. Feng, why is this here? Let’s take a look at the AddAddress method here. The modification method is: open class.phpmailer.php, find line 310, change private $to=Array() to public $to=Array().
Then send the email Add to the code:
$mail->to=Array(); $mail->AddAddress($email,$unm);
After writing this, there is no need to explain too much.
The above is the detailed content of Detailed example of how PHP determines whether the recipient has read the email. For more information, please follow other related articles on the PHP Chinese website!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment
