After phpmailer sends an email, it returns whether the recipient has read the email.

Source: Internet
Author: User
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:

 
 
This is the test content

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.