简体   繁体   English

如何检查端口465和587是否使用PHP打开?

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

I'm trying to use PHPMailer to send e-mails with SMTP and gmail. 我正在尝试使用PHPMailer发送带有SMTP和Gmail的电子邮件。 The exact script am using works on other servers but it is not working on this particular hosting company's server. 我使用的确切脚本适用于其他服务器,但它不能在这个特定的托管公司的服务器上运行。

I have checked the phpinfo() and it tells me that allow_url_fopen is on and there are no disabled_functions like fopen listed. 我检查了phpinfo() ,它告诉我allow_url_fopenon ,并且没有像fopen列出的disabled_functions

The script fails and it tells me either: 脚本失败,它告诉我:

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

or else 要不然

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. 我假设这是因为它无法连接,因为这在其他服务器上的工作和身份验证凭据是正确的。

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? 所以我更普遍地问,有没有办法可以使用PHP或jailshell ssh检查并查看端口是否实际打开?

You can check for open/available ports with fsockopen : 您可以使用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. ...其中5是呼叫失败前的超时秒数。

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. 请记住,阻止出站SMTP端口是一种非常常见的安全配置。 Back in the day, only port 25 was blocked, but I'm starting to see more and more SSL variants being blocked as well. 在当天,只有端口25被阻止,但我开始看到越来越多的SSL变种被阻止。

Most providers and hosting companies will only allow you to connect to their own SMTP server to prevent spammers from relaying junk mail. 大多数提供商和托管公司只允许您连接到自己的SMTP服务器,以防止垃圾邮件发送者转发垃圾邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM