use PHP to know if sent email has been opened

Asked

Viewed 2,831 times

2

I am very curious to know how to know if the email I sent was opened by the recipient. There is a way to know using PHP or some other language ?

2 answers

8


Disposition-Notification-To

What I recommend you do is add this to your email header:

Disposition-Notification-To: [email protected]

This is basically a request to the email client for you to receive a preview confirmation as soon as the email is opened. The recipient can disconnect the sending of this notification, of course.

Web Bugs

You can do this using an invisible image in the body of the email that calls a php script on your server, or at the suggestion of @Bacchus, take advantage of a legitimate email image (logo, footer, etc):

<img src="http://seusite.com.br/email_track.php?msgId=01abc02" />

So in the script you do something like:

if ( $_GET["msgId"] ) {
    $query = "update sent_mail set visualized_flag = 1 where mail_id = :id";
    $stmt = $conn->prepare($query);

    $stmt->bindParam(":id", $_GET["mailId"]);

    $stmt->execute();
    ...
}

But this practice is strongly discouraged and most email clients (including web clients) block this type of external content as well as not being good practice.

Additionally you can look for some Webservices that do this, such as the Get Notify.

  • opa muito obrigado. I will study this Webservices and see how it adapts to q e quero :)

  • Purpose you know how to tell me some forum or location where I can find content talking about how to develop extensions for Google Chrome ?

  • 1

    Dude, I’ve never stopped to learn this so I can’t help you, but a golden tip for anything is to devour the official documentation: https://developer.chrome.com/extensions/devguide. I searched for how develop google chrome extensions and found interesting links, take a look.

  • 2

    It’s actually a habit that I think is silly to use invisible images. Almost always in the email goes a logo on the signature, or some other visual detail, which serves as Beacon perfectly (I’m not disagreeing with the answer, just complementing).

  • It really is a better approach, I will complement the answer.

  • 1

    Only I noticed that some email clients are converting the images to the protocol data uri scheme, or by saving the images on the server to prevent possible security breaches, up to normal, because the request is made normally, but I’m afraid there may be e-mail clients that do this before the e-mail is read on a routine system. Even so it is the most functional solution.

Show 1 more comment

0

Another way would be using javascript that would send a POST or GET of the data to the target URL as soon as the email body loads. Example:

<html>
  <head>
     <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
     <script>
           $ . post ( 'http://seusite.com.br/email_track.php?msgId=01abc02');      
     </script>
  </head>
  <body>
     //Toda sua mensagem aqui.
  </body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.