tags:

views:

364

answers:

4

Hi, i'm new in php. I want to send an email to someone and afterwards i need to check if this mail could be received. How do i do that? Hope you guys understand my problem ;). Thanks in advance. Marc

+5  A: 

That's a really sticky question. The only real way is to have PHP monitor an inbox to check for "undeliverable message" notices you might get back. If you're really wanting to go forward with it, look into POP3 connectors for PHP. Like this: http://pecl.php.net/package/POP3

if (strpos(strtolower($subject), 'undeliverable') !== false){
    //do whatever you want with the address that couldn't be reached
}

You technically wouldn't need a compiled PHP extension for POP3 (especially if you're new to PHP)... you could connect and read messages by opening a socket and speaking mail server: http://www.adamsinfo.com/a-rudimentary-php-pop3-example/

brianreavis
A: 

One option is a Web Bug but these are far from 100% reliable, and are arguably not a nice way to behave. It won't differentiate between emails which are unread and those which are undelivered, for example because of a bad email address, and it is possible to read an email containing a Web Bug without triggering it.

In short you create an HTML email containing an element which has a URL on your site which is unique to that email. So if a client accesses that URL you can be sure that someone has read your email. Wikipedia gives this example:

For example, an e-mail sent to the address [email protected] can contain the embedded image of URL http://example.com/[email protected]. Whenever the user reads the e-mail, the image at this URL is requested. The part of the URL after the question mark is ignored by the server for the purpose of determining which file to send, but the complete URL is stored in the server's log file. As a result, the file bug.gif is sent and shown in the e-mail reader; at the same time, the server stores the fact that the particular e-mail sent to [email protected] has been read.

However, it is possible - probably quite likely - that someone can read your email without connecting to that URL. This may because:

  • A lot of email readers block such links by default because of privacy concerns precisely because of Web Bugs like this.
  • They read the email in text only, either because their email client is configured to do so or because it can't display HTML email, for example, a lot of mobile phone clients.

This is a often used option - both by spammers and more responsible marketers - but I probably wouldn't recommend it unless you fully understand its limitations and implications in terms of what people might think of you if you do use it.

Dave Webb
+1  A: 

If you're sending HTML mails, you could use a little trick:

  • generate a unique id for the mail you are sending (based on content and recipient)
  • include an image that is loaded from your webserver

    <img src="http://yourdomain.com/tracker.php?id=1234567" />

  • in tracker.php, log the id that called the script and send a 1px by 1px image

This won't work though, if the mail client does not download images from the internet when showing an email, as Thunderbird does, for example (IIRC Outlook does so too)

Cassy
Actually, Outlook probably blocks them too. And the GMail webreader won't show images by default either. And for good reason, since confirmation about received emails will also confirm that the email address is in use, thus a spammer will probably want to add this to his spamlist.
Workshop Alex
+1  A: 

There is no definite solution for this. Web bugs are a o.k. idea but they're dying out, as they are very problematic security wise and are blocked by default in every current E-mail client I know of. I would suggest a combination of checking a bounce inbox like brianreavis suggested, and in addition, requesting a delivery receipt using the following header line:

 Disposition-Notification-To:<[email protected]>

That way, you can get most negatives (bounced mails) as well as many positives (receipts). Sending the receipt can be blocked by the sender, but together with parsing error notifications, you should have fairly reliable system.

Pekka