How can I check if ports 465 and 587 are open with PHP?

后端 未结 1 786
无人共我
无人共我 2021-02-13 03:09

I\'m trying to use PHPMailer to send e-mails with SMTP and gmail. The exact script am using works on other servers but it is not working on this particular hosting company\'s se

1条回答
  •  感情败类
    2021-02-13 03:34

    You can check for open/available ports with fsockopen:

    $fp = fsockopen('127.0.0.1', 25, $errno, $errstr, 5);
    if (!$fp) {
        // port is closed or blocked
    } else {
        // port is open and available
        fclose($fp);
    }
    

    ...where 5 is the timeout in seconds until the call fails.

    This is probably due to a firewall issue where your hosting provider is blocking you from connecting to outbound sockets and/or specific ports. Keep in mind that it is a very usual security configuration to block outbound SMTP ports. Back in the day, only port 25 was blocked, but I'm starting to see more and more SSL variants being blocked as well.

    Most providers and hosting companies will only allow you to connect to their own SMTP server to prevent spammers from relaying junk mail.

    0 讨论(0)
提交回复
热议问题