After phpmailer sends an email, it returns whether the recipient has read the email. phpmailer sends the email
After using phpmailer to send emails, many people want to know if the recipient has read the emails? 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:
<Table width = "555" height = "50" border = "0" align = "center" cellpadding = "0" cellspacing = "0" background = "<? = $ Bg?> "> <Tr> <td> This is the test content </td> </tr> <td> </td> </tr> </table>
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.
How does phpmailer send emails? -Technical Q &
After setting the PHPMAILer parameters, add the recipient step, right? Assume that your recipient list is stored in the array $ aMails: [php] $ mail ){? ? ? ? $ OMail-> SetAddress ($ mail) ;}$ oMailer-> Send () ;?> [/Php] However, it is recommended that you use Sendmail to send Group emails to avoid sending failures. Do not send too many emails each time to avoid timeout. You can use the paging principle for Batch Sending.
In PHPMailer, how does one call the $ mail-> AddAddress () Recipient address?
I have used phpmailer to send emails. You can try it in my way.
If you define $ QQ as the QQ number of a pure number, then define another email format, and use $ UQQ = "@ qq.com" as an example, the receiving address is: $ ymail = "$ QQ ". "$ UQQ ";
Enter $ mail-> AddAddress ("$ ymail ");
For attachments, use $ mail-> AddAttachment ();
Reference: web technology favorites