За последние 24 часа нас посетили 24207 программистов и 1531 робот. Сейчас ищут 1255 программистов ...

Проблема с подключением к SFTP через fsockopen

Тема в разделе "PHP для профи", создана пользователем dakotta, 7 июл 2017.

Метки:
  1. dakotta

    dakotta Новичок

    С нами с:
    7 июл 2017
    Сообщения:
    3
    Симпатии:
    0
    Здравствуйте, подскажите, пожалуйста, не могу понять в чем может быть дело:
    Пытаюсь проверить существует ли e-mail используя этот скрипт: http://htmlweb.ru/php/example/is_e-mail.php
    На локальном xampp сервере все работает замечательно, но после заливки на хостинг здесь
    Код (Text):
    1. if ($connection = fsockopen ($mxhosts[0][$id], $port, $errno, $error, $this->timeout))   {
    возникает ошибка "110 connection timed out" и, соответственно, email всегда определяется ненастоящим.

    Посмотреть работу скрипта+phpinfo можно здесь: http://daria2.tom.ru/

    Код index.php:
    Код (Text):
    1.  
    2. <?php
    3. define('DEBUG_OK', true);
    4.  
    5. class CCheckMail
    6. {
    7.     var $timeout = 10;
    8.     var $domain_rules = array("aol.com", "bigfoot.com", "brain.net.pk", "breathemail.net",
    9.         "compuserve.com", "dialnet.co.uk", "glocksoft.com", "home.com",
    10.         "msn.com", "rocketmail.com", "uu.net", "yahoo.com", "yahoo.de");
    11.  
    12.     function _is_valid_email($email = "")
    13.     {
    14.         return preg_match('/^[.\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/', $email);
    15.     }
    16.  
    17.     function _check_domain_rules($domain = "")
    18.     {
    19.         return in_array(strtolower($domain), $this->domain_rules);
    20.     }
    21.  
    22.     function execute($email = "")
    23.     {
    24.         if (!$this->_is_valid_email($email)) return false;
    25.         $host = substr(strstr($email, '@'), 1);
    26.  
    27.         if ($this->_check_domain_rules($host)) return false;
    28.         $host .= ".";
    29.  
    30.         if (getmxrr($host, $mxhosts[0], $mxhosts[1]) == true) array_multisort($mxhosts[1], $mxhosts[0]);
    31.         else {
    32.             $mxhosts[0] = $host;
    33.             $mxhosts[1] = 10;
    34.         }
    35.         if (DEBUG_OK) print_r($mxhosts);
    36.  
    37.         $port = 25;
    38.         $localhost = $_SERVER['HTTP_HOST'];
    39.         $sender = 'info@' . $localhost;
    40.  
    41.         $result = false;
    42.         $id = 0;
    43.         while (!$result && $id < count($mxhosts[0])) {
    44.             if (function_exists("fsockopen")) {
    45.                 if (DEBUG_OK) print_r($id . " " . $mxhosts[0][$id]);
    46.                 if ($connection = fsockopen($mxhosts[0][$id], $port, $errno, $error, $this->timeout)) {
    47.                     fputs($connection, "HELO $localhost\r\n"); // 250
    48.                     $data = fgets($connection, 1024);
    49.                     $response = substr($data, 0, 1);
    50.                     if (DEBUG_OK) print_r($data);
    51.                     if ($response == '2') // 200, 250 etc.
    52.                     {
    53.                         fputs($connection, "MAIL FROM:<$sender>\r\n");
    54.                         $data = fgets($connection, 1024);
    55.                         $response = substr($data, 0, 1);
    56.                         if (DEBUG_OK) print_r($data);
    57.                         if ($response == '2') // 200, 250 etc.
    58.                         {
    59.                             fputs($connection, "RCPT TO:<$email>\r\n");
    60.                             $data = fgets($connection, 1024);
    61.                             $response = substr($data, 0, 1);
    62.                             if (DEBUG_OK) print_r($data);
    63.                             if ($response == '2') // 200, 250 etc.
    64.                             {
    65.                                 fputs($connection, "data\r\n");
    66.                                 $data = fgets($connection, 1024);
    67.                                 $response = substr($data, 0, 1);
    68.                                 if (DEBUG_OK) print_r($data);
    69.                                 if ($response == '2') // 200, 250 etc.
    70.                                 {
    71.                                     $result = true;
    72.                                 }
    73.                             }
    74.                         }
    75.                     }
    76.                     fputs($connection, "QUIT\r\n");
    77.                     fclose($connection);
    78.                     if ($result) return true;
    79.                 }
    80.             } else  break;
    81.             $id++;
    82.         } //while
    83.         return false;
    84.     }
    85. }
    86.  
    87. ?>
    88.  
    89. <?php
    90.  
    91. if (isset($_POST['email'])) {
    92.  
    93.     $str = $_POST['email'];
    94.     $alter = new CCheckMail();
    95.  
    96.     if ($alter->execute($str)) {
    97.         $result = "Email " . $_POST['email'] . " is real";
    98.     } else {
    99.         $result = "Email " . $_POST['email'] . " is fake";
    100.     }
    101. } else {
    102.     $result = "Please fill email";
    103. }
    104. ?>
    105. <div>
    106.     Check if email exists:
    107. </div>
    108. <form method="post" action="">
    109.     <input type="text" name="email" value=""/>
    110.     <input type="submit" value="Send"/>
    111.     <div>
    112.         <?php echo $result; ?>
    113.     </div>
    114. </form>
    115. <?php phpinfo() ?>
     
  2. Алекс8

    Алекс8 Активный пользователь

    С нами с:
    18 май 2017
    Сообщения:
    1.730
    Симпатии:
    359
    проверил как работает))
    Код (Text):
    1. Array ( [0] => Array ( [0] => aspmx.l.google.com [1] => alt1.aspmx.l.google.com [2] => alt2.aspmx.l.google.com [3] => aspmx2.googlemail.com [4] => aspmx3.googlemail.com [5] => aspmx4.googlemail.com [6] => aspmx5.googlemail.com ) [1] => Array ( [0] => 10 [1] => 20 [2] => 20 [3] => 30 [4] => 30 [5] => 30 [6] => 30 ) ) 0 aspmx.l.google.com220 mx.google.com ESMTP h190si933522lfh.327 - gsmtp 250 mx.google.com at your service 250 2.1.0 OK h190si933522lfh.327 - gsmtp 250 2.1.5 OK h190si933522lfh.327 - gsmtp
    2. E-mail: httpwwwtumblrcomethereal04@tumblr.com
    3. Результат: существует
    а по факту такой почты нет)
     
  3. dakotta

    dakotta Новичок

    С нами с:
    7 июл 2017
    Сообщения:
    3
    Симпатии:
    0
    @Алекс8 Здравствуйте! Спасибо за ответ.
    У меня на локальном тоже приняло этот адрес (плохо, что приняло несуществующий, но пока пусть будет так).
    Вы не знаете почему на хостинге могут возникать проблемы ``connection timed out`` при вызове
    if ($connection = fsockopen($mxhosts[0][$id], $port, $errno, $error, $this->timeout)) {
    ?
    У меня на сервере daria2.tom.ru этот email не принимается по этой причине, как и любой другой валидный :(
     
  4. Алекс8

    Алекс8 Активный пользователь

    С нами с:
    18 май 2017
    Сообщения:
    1.730
    Симпатии:
    359
    @dakotta у меня и на daria2.tom.ru отвечает)) только там говорит другое)

    Код (Text):
    1. Array ( [0] => Array ( [0] => aspmx.l.google.com [1] => alt1.aspmx.l.google.com [2] => alt2.aspmx.l.google.com [3] => aspmx2.googlemail.com [4] => aspmx3.googlemail.com [5] => aspmx4.googlemail.com [6] => aspmx5.googlemail.com ) [1] => Array ( [0] => 10 [1] => 20 [2] => 20 [3] => 30 [4] => 30 [5] => 30 [6] => 30 ) ) 0 aspmx.l.google.com1 alt1.aspmx.l.google.com2 alt2.aspmx.l.google.com3 aspmx2.googlemail.com4 aspmx3.googlemail.com5 aspmx4.googlemail.com6 aspmx5.googlemail.com
    2. Check if email exists:
    3.  
    4. Email 1httpwwwtumblrcomethereal04@tumblr.com is fake
     
  5. dakotta

    dakotta Новичок

    С нами с:
    7 июл 2017
    Сообщения:
    3
    Симпатии:
    0
    @Алекс8 Да, все верно, там отвечает, но всегда fake и для валидных и для невалидных адресов, потому что возникает ошибка на строке с fsockopen. Сделала var_dump ошибки.
    Например, я вводила свой валидный e-mail, получила:
    Код (Text):
    1.  
    2. Array ( [0] => Array ( [0] => gmail-smtp-in.l.google.com [1] => alt1.gmail-smtp-in.l.google.com [2] => alt2.gmail-smtp-in.l.google.com [3] => alt3.gmail-smtp-in.l.google.com [4] => alt4.gmail-smtp-in.l.google.com ) [1] => Array ( [0] => 5 [1] => 10 [2] => 20 [3] => 30 [4] => 40 ) ) 0 gmail-smtp-in.l.google.com
    3. string(8) "Errors! "
    4. string(32) "host: gmail-smtp-in.l.google.com"
    5. string(8) "port: 25"
    6. string(10) "errno: 110"
    7. string(27) "error: Connection timed out"
    8. string(11) "timeout: 10"
    9.  
    10. 1 alt1.gmail-smtp-in.l.google.com
    11. string(8) "Errors! "
    12. string(37) "host: alt1.gmail-smtp-in.l.google.com"
    13. string(8) "port: 25"
    14. string(10) "errno: 110"
    15. string(27) "error: Connection timed out"
    16. string(11) "timeout: 10"
    17.  
    18. 2 alt2.gmail-smtp-in.l.google.com
    19. string(8) "Errors! "
    20. string(37) "host: alt2.gmail-smtp-in.l.google.com"
    21. string(8) "port: 25"
    22. string(10) "errno: 110"
    23. string(27) "error: Connection timed out"
    24. string(11) "timeout: 10"
    25.  
    26. 3 alt3.gmail-smtp-in.l.google.com
    27. string(8) "Errors! "
    28. string(37) "host: alt3.gmail-smtp-in.l.google.com"
    29. string(8) "port: 25"
    30. string(10) "errno: 110"
    31. string(27) "error: Connection timed out"
    32. string(11) "timeout: 10"
    33.  
    34. 4 alt4.gmail-smtp-in.l.google.com
    35. string(8) "Errors! "
    36. string(37) "host: alt4.gmail-smtp-in.l.google.com"
    37. string(8) "port: 25"
    38. string(10) "errno: 110"
    39. string(27) "error: Connection timed out"
    40. string(11) "timeout: 10"
    Email dsbaranova@gmail.com is fake