|Detecting Email Sent Status|
Hi, I am sending email through php, and want to know how to detect bounced email's, received email, and opended email. I can't find anything online other than the standard php email header information. How do I go about measuring this? I would ideally like to record this in a database once I get the result.
Thanks in advance.
Its tough to check those stats with simple functions, imo you ll need a proper MTA to do it efficiently. For opened email you can probably put a tracking pixel image in your email content
There is no easy/direct way of doing what you want. FYI
The easiest thing you can check is if the email is properly sent via your own mail server. If you use PHP's mail function to send your email, set it up like:
$emailSent = mail(...);
The emailSent variable will be a boolean indicating whether the mail server could or could not send the email.
But this will not tell you if the email gets bounced or if the email gets opened, or if it is actually received. Frankly, only bounced/opened matter. If an email is not bounced, it is safe to assume it was received. If an email is opened, it is safe to assume it was received. If an email is bounced, it is safe to assume it was not received. Etc.
I have not done this, I am just pondering. You could set the "from" and "reply to" parameters of the email to a specific email address (email@example.com); something generic that you don't actually use. You can then set up your server to route/"pipe" emails sent to this address to a PHP script on your server. I know this can be done; but I have not explored it myself.
Now if you can get this email to your PHP script... you can then scrape the message to see if it is a "bounce" message. Why? If an email gets bounced, the opposing mail server will usually send the bounce message back to you (via the from/reply to address). If it IS a bounce message... scrape whatever info you need from the email and mark it as such in your DB.
This is also something you cannot easily/quickly do. But here's my thoughts on it. Place an "image" in your email message, a la:
Then, create the PHP script. Have it use the parameter (ref; etc) to uniquely identify the email (you would need to store such info in your DB when emails are sent, FYI). Whenever this script gets requested, it represents an emailing being read/loaded, or being "opened". So, setup the script to update your DB to reflect this. When someone requests this "file", it should grab the identifier and update your DB to show it was "received" and "opened". Then, to be "kosher", have your script output some junk image data (probably a simple white image of 1px by 1px with proper headers/etc).
Hope that can help.
This is not likely to be a pure PHP solution. You'll need to parse the actual mail server logs (which you likely could do in PHP, if you have access to them) but I have one client who uses surgemail for exactly this reason.
You'll need access to the logs generated by whatever the actual program is on the server (i.e., qmail, etc.) to get at the delivery status messages.
Ok, so I think the 1px x 1px image solution presents a solid method of recording whether a user has opened an email providing the image loads. I would imagine, for some mail clients such as Hotmail, it would be wise to force this image to load somehow to prevent having to hit the "show content" link which sometimes displays. Other than this issue, I think this is good, so if someone know why the image does not always automatically show, that would be great.
In terms of detecting a bounce, this seems to be the harder part. I would be interested to know if there is any other way of recording this other than trauling through mail server logs. I need to be able to detect down to the level of per email address bounced, per campaign sent.
Thanks for the input so far. Solved two of three issues, with the remaining "unopened emails" equaling: unopened emails = total emails sent - bounced - opened emails.
Is it possible that a solution using $headers .= "Return-Path: firstname.lastname@example.org"; could work? Is there someway I could receive confirmation of mail bounced at this address, then track which emails and campaigns the return path is indicating are bounced?
|I think the 1px x 1px image solution presents a solid method of recording whether a user has opened an email providing the image loads. |
Unfortunately, it's not reliable, a search here should turn up some posts that have proven me wrong on that one. :-) For example, web based clients that do not show images by default, among them gmail, Horde, etc . . . often they will read the text message and never "click here to see message with images."
Ok, so if there is no way to force the download of an image in web based email clients, what other options are there?
Also, it would appear that measuring the bounce status can be done with a Return Path, but you need to process the email that gets sent back. How is this possible. Steve Lim's post at the bottom of this page outlines the steps:
|so if there is no way to force the download of an image in web based email clients |
Not only web mail, Outlook here at work is configured not to download images, get a message at the top "Click here to download images..."
Can't remember off hand if Outlook Express or Thunderbird can also be set to not download images.
Thanks Mike, but unfortunately due to the stability issue of the 1px x 1px image, I have no method of recording reports data unless I go through the mail logs for both received and bounced mail multiple times. Is this the only truly accurate way to do this, or is their some wizardry someone knows of?
Also, what is the best way to go through the logs? At a dedicated mail address, and if so, I would need to determine between, campaign id. Is this possible from the subject or header elements somehow?