How to know mail is send and read by user when sending mail using SMTP,PHPmailer

16,048
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/

require ('../class.phpmailer.php');

try {
        $mail = new PHPMailer(true); //New instance, with exceptions enabled

        $body             = "Please return read receipt to me.";
        $body             = preg_replace('/\\\\/','', $body); //Strip backslashes

        $mail->IsSMTP();                           // tell the class to use SMTP
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->Port       = 25;                    // set the SMTP server port
        $mail->Host       = "SMTP SERVER IP/DOMAIN"; // SMTP server
        $mail->Username   = "EMAIL USER ACCOUNT";     // SMTP server username
        $mail->Password   = "EMAIL USER PASSWORD";            // SMTP server password

        $mail->IsSendmail();  // tell the class to use Sendmail

        $mail->AddReplyTo("[email protected]","SOMEONE");

        $mail->From       = "[email protected]";
        $mail->FromName   = "SOMEONE";

        $to = "[email protected]";

        $mail->AddAddress($to);

        $mail->Subject  = "First PHPMailer Message[Test Read Receipt]";

        $mail->ConfirmReadingTo = "[email protected]"; //this is the command to request for read receipt. The read receipt email will send to the email address.

        $mail->AltBody    = "Please return read receipt to me."; // optional, comment out and test
        $mail->WordWrap   = 80; // set word wrap

        $mail->MsgHTML($body);

        $mail->IsHTML(true); // send as HTML

        $mail->Send();
        echo 'Message has been sent.';
} catch (phpmailerException $e) {
        echo $e->errorMessage();
}
?>

Some modification need to be done in above script.

  1. Configure SMTP mail server.

  2. Set the correct FROM & FROM Name ([email protected], SOMEONE)

  3. Set the correct TO address

from

also

  1. Delivery reports and read receipts in PHP mail
Share:
16,048
Jigar Oza
Author by

Jigar Oza

Updated on June 13, 2022

Comments

  • Jigar Oza
    Jigar Oza almost 2 years

    is anybody know any solution for below problem

    in my project, i am send email to client using smtp and php mailer and gmail script. so when i am send mail gmail send mail to particular client. for that i am passing gmail login and user name which is valid. all mail are sending properly. but sometime it may happen that some client not receive mail and at that time i am not able to get or trace any error. so i there any way, when i am sending mail to client , and when client get it and read it at that time i got any kind of confirmation.

    Please if anybody have any idea , help me out.