This article mainly introduces the phpmailer method for returning recipients to read emails after sending emails. This function is very simple and practical. For more information, see phpmailer, do you want to know if the recipient has read the email? Generally, we cannot know this. Is there a solution?
There is a simple solution to this problem. we know that the Mail content can be sent in html format, and we can insert images into the content, so the key is in this picture.
Assume that the email content is as follows:
The file content. php code is as follows:
How to write $ bg? What if the email is sent to multiple people? How can we differentiate them here?
Suppose the link is like this: http://www.xxx.com/image.php? Email = $ email and check the image. php code.
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 this. Therefore, the content of the email I sent is as follows:
<?php ob_start(); include_once("content.php"); $content=ob_get_contents(); ob_end_clean(); ?>
Here, we have not replaced the background image in the email content. the following problem will be solved gradually.Part of the code for sending an email 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? To identify the contact who has read the email, the background image 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 Mail content we see becomes like this: http://www.domain.com/image.php? Email = aaa@sina.com and so on.
Note that there is another problem here. after you execute the above code, you will find a problem. three messages are sent to the first person, two messages are sent to the second person, and one message is sent to the third person, why? Here we will look at the AddAddress method. The modification method is: open class. phpmailer. php, find row 310, and change private $ to = Array () to public $ to = Array ().
Then add the following to the code for sending the email:
$mail->to=Array();$mail->AddAddress($email,$unm);
Here, we don't need to explain it too much.