Chandan Cm
Chandan Cm

Reputation: 1

How to Verify the email sent by PHP, not by syntax; but by status

I did verify email address entered in the textbox, before sending mail i.e by syntax. But How to verify or validate the correct email address using PHP?

if(mail($emailto)) {
   echo("status=Sent");
}
else {
   echo("status=Failed");
}

For example if you enter [email protected], it accepts as a valid email id! Hw do we know it exists or not?

Upvotes: 0

Views: 1252

Answers (3)

Explosion Pills
Explosion Pills

Reputation: 191729

It's impossible to tell whether an email address exists (unless the server you are trying to contact has some sort of API for this). You can, however, check whether the domain can be emailed to:

function checkEmailDomain($email) {
   list(,$domain) = explode('@', $email);
   if (checkdnsrr($domain, 'MX')) {
      return TRUE;
   }
   else if (checkdnsrr($domain, 'A')) {
      return TRUE;
   }
   return FALSE;
}

Note that this is not 100% dependable either. If you want to use it, it should be purely advisory.

Upvotes: 0

moonwave99
moonwave99

Reputation: 22817

The user will tell it for you when reading :)

You can't as already stated, so be sure to provide a "please resend me the email" link around, so the user will be able to put the correct email [if he or she was wrong], or just to send it again if there were any issues with you smtp server.

Upvotes: 0

L0j1k
L0j1k

Reputation: 12625

You can't. That's the nature of the internet: You can't be absolutely certain any host (let alone an account on the host) is in a given state at any time unless you have control over the host.

You can tell a failure by a return message from the mailer daemon specifically stating that the delivery attempt failed. But that is a courtesy most private mailers will not extend to you.

You will almost NEVER get a return verification email in the case of successful delivery unless you have specifically set up the server to behave that way.

Upvotes: 3

Related Questions