0

So, the thing is I was working on the application in which I need to check that the email id is currently active or in working state or not, for which I used fsockopen() function of PHP, now what happens is in my localhost XAMPP its working fine but when I uploaded it to the server bigrock it is giving an error as:

Message: fsockopen(): unable to connect to ssl://gmail-smtp-in.l.google.com:465 (Connection timed out)

My code is.

function email_validation($email){
    list($name, $domain)=explode('@',$email);
    $max_conn_time = 30;
    $sock='';
    $port = 25;
    $max_read_time = 5;
    $users=$name;
    $hosts = array();
    $mxweights = array();
    getmxrr($domain, $hosts, $mxweights);
    $mxs = array_combine($hosts, $mxweights);
    asort($mxs, SORT_NUMERIC);
    $mxs[$domain] = 100;
    $timeout = $max_conn_time / count($mxs);
        while(list($host) = each($mxs)){
        $host="ssl://".$host;
        if($sock = fsockopen($host, 465, $errno, $errstr, 10)){
        stream_set_timeout($sock, $max_read_time);
        break;
        }
    }
}
fool-dev
  • 7,671
  • 9
  • 40
  • 54
  • Any help will be more than sufficient for me. – Rishi Agrawal Feb 07 '18 at 09:38
  • You sure about that protocol? `ssl://gmail...` ? – CD001 Feb 07 '18 at 09:45
  • As an aside - the only way you can *really* know whether an email exists or not is to email it. All `getmxrr()` will tell you is whether the receiving domain is configured to receive emails. You should probably also [check that the email is of a valid format](http://php.net/manual/en/filter.examples.validation.php) before looking up the MX record on the domain. – CD001 Feb 07 '18 at 09:50
  • @CD001 is there any other way through which i can check whether email id is existing or not in php. – Rishi Agrawal Feb 07 '18 at 11:23
  • Yes - but it's not normally necessary, or even a good idea - checking the format of the email and the MX record on the domain is enough: https://stackoverflow.com/questions/19261987/how-to-check-if-an-email-address-is-real-or-valid-using-php - if you need to verify the email address fully you should send an email to that address with a verification link in it. – CD001 Feb 07 '18 at 12:02
  • ok thank you, it means that their is no need of using fsockopen() in the code , only with the help of checkdnsrr() and getmxrr() i can verify the email id. – Rishi Agrawal Feb 07 '18 at 13:12

1 Answers1

0

You can use something like this by parsing the domain of the email:

if(checkdnsrr(array_pop(explode("@",$email)),"MX")) {
     // valid email    
}

http://php.net/manual/en/function.checkdnsrr.php

Amit Merchant
  • 1,045
  • 6
  • 21