0

Possible Duplicate:
How to check if an email address exists without sending an email?

Possible duplicate:

How to check if an email exists without sending an email?

I have a very big database with users (over 50000) and there are lots of automated e-mails the site sends out.

The problem is, quite a few of the addresses in the database (that users registered with years ago) have expired or have been deleted or no longer exist for whatever reason.

This creates an issue, because each user should have a valid e-mail.

I've been trying to find out if there's a way to detect whether an e-mail address is active, so we could update the database and prompt those users to enter a new e-mail? Something like a ping for e-mail addresses?

There's some code here that I've tried to figure out but to no avail:

http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/smtpvalidateclassphp/

Does anyone have a solution?

Please note that I need a PHP solution, not command line since I have 50k e-mails to check.

Community
  • 1
  • 1
robert
  • 811
  • 3
  • 16
  • 28
  • 2
    most mailing lists would check for bounces and process them accordingly. –  Jan 19 '12 at 21:27
  • 2
    ping for email = send email, see if you get any bounces. – Marc B Jan 19 '12 at 21:27
  • FYI, there really isn't too much of a difference, performance wise, between what a command line script and a PHP script could do. The bottleneck in both cases is the network. – cdeszaq Jan 19 '12 at 21:30

2 Answers2

2

Two things, first you should stop the influx of potentially in-valid email addresses by implementing a 'closed-loop' email verification system. Basically, when a user signs up for your site, you send an email with a link confirming their email address, and when they confirm, their account gets full access to your site.

Secondly, there is no real way to determine if an an email address is invalid strictly using PHP. I had to tackle this problem a few months ago, and we ended up using the mail-server to tell us if an email address has been bounced back or not. When your mail server sends an email, and the email cannot be delivered, the recipient mail-server will respond with a bounce notification to your mail-server which includes information as to why the email was bounced. Information such as a Delivery Status Notification (DSN) code which identifies why the email address couldn't be delivered.

Some example codes:

  • 511: Bad Mailbox
  • 512: Bad System
  • 516: Mailbox Moved

These codes are made up of a prefix (4 or 5) to indicate a transient (temporary) or permanent failure. The following two digit code indicates an error range; two digit codes between 10 and 19 indicate an error relating to the email address, whereas codes between 20 and 29 indicate an error relating to the email mailbox.

From these codes you can determine, based on business requirements, a 'hard bounce' or a 'soft bounce'. A hard bounce would be something like 511 (bad mailbox), where it's certain that this email address is not currently valid. A soft bounce would be something like 445 (network congested), which indicates that it was a temporary issue as to why the email could not be delivered.

So in your instance, you could send out an email blast, and then track the bounces on your mail server. By looking at each bounce and the respective DSN code, you can flag whether an account's email is valid or not (we used PHP to gain access to the mail server and parse the bounce notifications for the DSN codes)

Here is more information on DSN codes.

-- Edit --

As Dagon wisely mentioned, you can pipe bounced emails into a PHP script upon their receipt. To do this you will need to read up on your mailserver config, but ours looks similar to the following:

bouncehandler   unix    -       n       n       -       -       pipe
user=nobody argv=/usr/bin/php /path/to/BounceHandler.php
<% end %>
Community
  • 1
  • 1
Mike Purcell
  • 19,847
  • 10
  • 52
  • 89
1

The only way to check if an e-mail address is expired or not is to send an e-mail message to it and see if you get a response. But note that doing so may be considered spamming, since it is an unsolicited message.

You can check if an e-mail address if properly formed, and if the mail server it specifies actually exists, but thats about it. There is no way that I know of to check if the account exists (and if a human is reading the mail sent there) without sending a mail with a link and requesting that the user click the link.

cha0site
  • 10,517
  • 3
  • 33
  • 51