how to verify email is valid

2.6k views Asked by At

I tried many method to track am email is valid or not before send it. Am using php mailer and swift mail to send emails.Many website told refer the mx record. But it returns only the domain is valid or not. NOt returns the email. For example if i have a domain example.com and i created only [email protected] ,if i tried to send mail to [email protected] also returns the email is valid. But i need the result for [email protected] as invalid before sending this email.

Just like the process in http://www.email-validator.net/

4

There are 4 answers

0
Nir Kornfeld On BEST ANSWER

There is no way to be 100% sure the email is vaild.

What you can try to do is connect to the mail server, start a mail session and "ask" the server to accept mail for the given address.

Some mail servers will return an error if the address is not listed, but others will accept any address, as long as it is in the server's scope.

As for the site you've mentioned, try to check this address for instance: [email protected]

You will get an answer that the server accepted this address, but it doesn't mean it's a valid one...

0
AudioBubble On

Try just building

$APIUrl = 'http://www.email-validator.net/api/verify';
$Params = array('EmailAddress' => $Email,
                'APIKey' => '[your API key]');
$Request = @http_build_query($Params);
$ctxData = array(
     'method' => "POST",
     'header' => "Connection: close\r\n".
     "Content-Length: ".strlen($Request)."\r\n",
     'content'=> $Request);
$ctx = @stream_context_create(array('http' => $ctxData));

// send API request
$result = json_decode(@file_get_contents(
    $APIUrl, false, $ctx));

// check API result
if ($result && $result->{'status'} > 0) {
    switch ($result->{'status'}) {
        // valid addresses have a {200, 207, 215} result code
        case 200:
        case 207:
        case 215:
                echo "Address is valid.";
                break;
        case 114;
                // retry
                break;
        default:
                echo "Address is invalid.";
                echo $result->{'info'};
                echo $result->{'details'};
                break;
    }
} else {
    echo $result->{'info'};
}

into your code

0
martinstoeckli On

Unfortunately it is not possible to verify reliably if an email address is valid or not, because often the server will not send back an error, if the address doesn't exist. This is necessary, because otherwise spammers could just try out email adresses, and could find out which ones are valid and which are not.

0
rathourarv On

There is no way to verify if the email is valid or not until you send it. We are using AWS Simple Email Service to send emails. It's good that we can configure the bounce action with it.

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-bounce.html

You can specify the SNS topic to send an event when the email is bounced. Additionally, you can process the event and take action according to the error code.