You are here

PHP send email request read receipt

When users using Emails function in some web base application (like sugarcrm, joomla), they might need to request read receipt from the recipients.
Here is a simple tutorial on how to add in the “Request read receipt” in email while send out email thru PHP.

I am using the phpmailer class to develop the feature, please download it from the source forge.

Here is the simple script to send out email and request for read receipt.

<?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("someone@something.com","SOMEONE");
        $mail->From       = "someone@something.com";
        $mail->FromName   = "SOMEONE";
        $to = "other@something.com";
        $mail->AddAddress($to);
        $mail->Subject  = "First PHPMailer Message[Test Read Receipt]";
        $mail->ConfirmReadingTo = "someone@something.com"; //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 (someone@something.com, SOMEONE)
3. Set the correct TO address

 

source myhow2guru