xRobot
xRobot

Reputation: 26567

How to know if an email address exist through PHP?

Some people have subscribed to my blog by entering their email address.

But some of the email addresses don’t exist.

How can I know if these email addresses are valid when I send an email to these email addresses?

Upvotes: 3

Views: 2498

Answers (4)

Yeroon
Yeroon

Reputation: 3243

You can do an MX record lookup with:

$result = getmxrr($hostname, $mxHosts);
if(count($mxHosts) < 1){
   //no MX records found
}

This will prevent your users from using the '[email protected]'-type of input. See the manual page on php.net: http://www.php.net/manual/en/function.getmxrr.php

Upvotes: 1

icanhasserver
icanhasserver

Reputation: 1064

You'll never be 100% sure that a provided email address really exists.

One way would be to use the SMTP VRFY command to instruct the destination mail relay to confirm the recipient. But many servers don't provide this feature. It also requires direct SMTP communication to do the check.

Even when the destination server doesn't refuse your recipient, the recipient may not exist, as some servers accept all incoming emails and bounce them back at a later stage.

You may implement the following commands (or use one of the many PHP scriplets that do it for you):

HELO <your server name>
MAIL FROM: <>
RCPT TO: <[email protected]>
QUIT

Upvotes: 2

Pablo Venturino
Pablo Venturino

Reputation: 5318

As far as I know, you can't. You'll know that the email is not valid when you fail to deliver the email, whether it's because the domain doesn't exists or the account doesn't exists on that domain.

If you want to make sure only real accounts are used to subscribe, send a confirmation email where the user clicks a link to validate his account (like casablanca says here).

Upvotes: 2

casablanca
casablanca

Reputation: 70701

Send them a confirmation mail with a link, and activate the subscription only if they click that link.

Upvotes: 9

Related Questions