Reputation: 1760
I'm sending a bunch of emails out through a script in PHP, and I want to analyse the outcome of each so I know if it was delivered or not.
Anyway of doing that through PHP?
Upvotes: 3
Views: 3386
Reputation: 24815
If a mail has been send can be detected easily, detecting if it has been delivered is a different case.
What you could do is implement a 1px image in the e-mail, which is hosted on your site. The image is ofcourse created by PHP, so you can give it an unique ID to detect if the image has been loaded. If you disable the cache on it, you could probably even detect how often the mail gets read.
Creating image like this:
header('Content-Type: image/png');
$im = @imagecreate(1, 1);
$background_color = imagecolorallocate($im, 255, 255, 255); // make it white
imagepng($im,"image.png");
imagedestroy($im);
Store this on a page called image.php (or something, up to you). Store also in a database which e-mails has been send and create a unique ID for it (md5 or sha1 hash would be nice)
Something like:
$id = sha1([ID FROM DATABASE] + salt)
store this also in the database on the row of the e-mail.
Then link to the image with the ID
<img src="http://www.example.com/image.php?id=SHA1HASHHERE" />
This way you can track
Upvotes: 3
Reputation: 13275
You can check it's been sent, but checking it's been delivered is another thing entirely.
In fact, I can't think of any way to confirm it's been delivered without also checking it gets read, either by including a 1x1 .gif that is requested from your server and logged as having been accessed, or a link that the user must visit to see the full content of the message.
Neither are guaranteed (not all email clients will display images or use HTML) and not all 'delivered' messages will be read.
You can of course, monitor your reply-to
address for any bounced mail which will let you say with certainty that a message hasn't been delivered.
Upvotes: 4
Reputation: 45568
There is no really good method for that - however, you can embed an image with an url that contains the mail address and log requests.
Upvotes: 2