如何检查端口465和587是否已使用PHP打开? [英] How can I check if ports 465 and 587 are open with PHP?

查看:344
本文介绍了如何检查端口465和587是否已使用PHP打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHPMailer发送带有SMTP和gmail的电子邮件.使用的确切脚本可以在其他服务器上使用,但是不能在该特定托管公司的服务器上使用.

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 server.

我检查了phpinfo(),它告诉我allow_url_fopenon,并且没有列出disabled_functions之类的disabled_functions.

I have checked the phpinfo() and it tells me that allow_url_fopen is on and there are no disabled_functions like fopen listed.

该脚本失败,它告诉我:

The script fails and it tells me either:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 

否则

SMTP Error: Could not authenticate.

我认为这是因为它无法连接,因为同样可以在其他服务器上工作并且身份验证凭据是正确的.

I'm assuming this is because it can not connect, because again this work on other servers and the authentication credentials are correct.

所以我更普遍地问,有没有一种方法可以使用PHP或jailshell ssh来检查端口是否真正打开?

So I ask more generally, is there a way I can use PHP or jailshell ssh to check and see if the ports are actually open or not?

推荐答案

您可以使用fsockopen检查开放/可用端口:

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);
}

...其中5是直到呼叫失败的超时时间(以秒为单位).

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

这可能是由于防火墙问题,您的托管服务提供商阻止您连接到出站套接字和/或特定端口.请记住,阻止出站SMTP端口是一种非常常见的安全配置.过去,只有端口25被阻止,但是我也开始看到越来越多的SSL变种也被阻止.

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.

大多数提供商和托管公司将只允许您连接到自己的SMTP服务器,以防止垃圾邮件发送者中继垃圾邮件.

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

这篇关于如何检查端口465和587是否已使用PHP打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆