Skip to content
Advertisement

PHP: Check who had read sent email?

I am sending email to some users and wants to know who had read it, means if some one had read that email then a log file will maintain which contain the email address of that user with date/time/IP. For this I send a javascript function with the email (html template) which just alert the email address of the user when ever a user opens that email like:

for($n=0; $n<sizeof($checkBox); $n++){
        $mail = new PHPMailer();
        $mail->IsHTML(true);
        $mail->Subject = $subject;
        $function = "<script language='javascript'>function stats(emailId){alert(emailId);}</script>";
        $bodyOpen = "<body onload='stats(".$checkBox[$n].");'>"; 
        $msg_body .= $body .= "<table><tr><td>Hello Everyone</td></tr></table></body>";
        $mail->Body = $function.$bodyOpen.$msg_body;
        $mail->WordWrap = 50;
        $mail->FromName = 'Muhammad Sajid';
        $mail->IsMAIL();        
        $mail->From = 'webspot49@gmail.com';
        $mail->AddAddress($checkBox[$n]);
        $sent = $mail->Send();
    }

the html template works fine and shows an alert popup on page load but it does not works if I use to send this html template.

And I only want to solve this issue using PHP5.x.x / javascript, no other software or third party tool. Any help..?

Advertisement

Answer

Add Header to email:

Disposition-Notification-To: you@yourdomain.com

As mentioned above it’s not reliable and it’s better to do something like this:

<img src="http://yourdomain.com/emailreceipt.php?receipt=<email of receiver>" />

And log it in a database, although again this is restricted by the email client’s ability to show images and sometimes it may even put the mail into junk because it doesn’t detect an image… a workaround that would be to actually outputting an image (say your logo) at the end of that script.

Edit: A quick lookup at the phpmailer class gave me the following:

$mail->ConfirmReadingTo = 'yourown@emailaddress.com';

but it’s the same as the Disposition-Notification-To method above.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement