Our Blog

Sent E-mail read or un-read - PHP Code

We are using gmail, yahoo, hotmail etc to send emails to our friends, relatives etc. We dont know whether the email that we sent was read by the recipient or not. To get the read receipts, we need paid accounts from the Mail providers.

Here i am going to show you a simple php program script to get read receipts of the emails that we sent.

$user_id = $_GET['user_id'];

If ( $user_id )
{
    $FileName = $id.".txt";
    $ourFileHandle = fopen($FileName, 'w') or die("can't open file");
    fclose($ourFileHandle);
}
else
{
    $to = "jhon@gmail.com"; //to address

    $subject ="Read Receipt Email";

    $message = "Testing whether the read receipt script works or not";
    $message = "     $headers  = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= 'From: kelly@ymail.com' . "rn";

    if (mail($to, $subject, $message, $headers) )
    {
        echo "Mail sent successfully";
    }
    else
    {
        echo "failed to send mail";
    }
}

?>

Lets call this php script page name as email.php and the website domain name as www.example.com. The url of this page is http://www.example.com/email.php.

      Now the user_id parameter contains a   When you open this page (http://www.example.com/email.php) on the browser, then the script first tries to read the get parameter user_id and checks whether there is any value in the parameter.

  •     As there is no value for the user_id parameter, the script goes to the else part and sends an email to the user. The important part here is the image tag in the message.
  •     Once the user receives an email and opens it, the html image tag tries to download a zero pixel image from the site. The url of the image is http://www.example.com/email.php?user_id=jhon@gmail.com value. The php script goes to the section and creates an empty file with jhon@gmail.com.txt. The creation of the empty file indicates that the user read the email.


 

Recent Posts
PHP 7 New Features and

What is PHP 7? PHP 7 is a major release of PHP programming language and is touted to be a revolution in the way web applications can be developed and delivered for mobile to enterprises and the...



Protect website from Sql injunction and

1.Keep software up to date If you are using third-party software on your website such as a CMS or forum, you should ensure you are quick to apply any security patches. 2.SQL injection SQL...