PHPMailer 无法连接到 SMTP 主机

发布于 2024-11-10 00:01:04 字数 2071 浏览 3 评论 0原文

出现以下错误:

SMTP ->错误:无法连接到服务器:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。 (0) SMTP 错误:无法连接到 SMTP 主机。发送此邮件时出现问题!

这是我的配置文件设置,因为我遵循了这个 PHPMailer 教程

// Configuration settings for My Site

// Email Settings
$site['from_name'] = 'Manish Dekavadiya'; // from email name
$site['from_email'] = 'manish@<my-domain>.com'; // from email address

// Just in case we need to relay to a different server,
// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = "smtp.<my-domain>.com";
$site['smtp_port'] = 587;
$site['smtp_username'] = "manish@<my-domain>.com";
$site['smtp_password']="<password>";

并使用了教程中提到的邮件程序类和扩展类,如下所示:

/*****sendmail.php****/

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');

// Grab the FreakMailer class
//echo $_SERVER['DOCUMENT_ROOT'];
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');

// instantiate the class
$mailer = new FreakMailer();

// Set the subject
$mailer->Subject = 'This is a test';
 $mailer->SMTPDebug = 1;
// Body
$mailer->Body = 'This is a test of my mail system!';

// Add an address to send to.
$mailer->AddAddress('[email protected]', 'Manish Dekavadiya');

if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();

当我尝试 phpmailer 文档 @ 中给出的示例时,也遇到另一个错误示例/test_smtp_gmail_basic.php

SMTP ->错误:无法连接到服务器:php_network_getaddresses: getaddrinfo 失败:没有这样的主机 已知。 (0) SMTP 错误:无法 连接到 SMTP 主机。有一个 发送此邮件时出现问题!

所以一定是设置或配置错误。不可能有代码错误。

getting following error:

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!

This is my config file setting as I have followed this PHPMailer tutorial

// Configuration settings for My Site

// Email Settings
$site['from_name'] = 'Manish Dekavadiya'; // from email name
$site['from_email'] = 'manish@<my-domain>.com'; // from email address

// Just in case we need to relay to a different server,
// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = "smtp.<my-domain>.com";
$site['smtp_port'] = 587;
$site['smtp_username'] = "manish@<my-domain>.com";
$site['smtp_password']="<password>";

and used mailer class and an extended class as mentioned in tutorial as following:

/*****sendmail.php****/

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');

// Grab the FreakMailer class
//echo $_SERVER['DOCUMENT_ROOT'];
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');

// instantiate the class
$mailer = new FreakMailer();

// Set the subject
$mailer->Subject = 'This is a test';
 $mailer->SMTPDebug = 1;
// Body
$mailer->Body = 'This is a test of my mail system!';

// Add an address to send to.
$mailer->AddAddress('[email protected]', 'Manish Dekavadiya');

if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();

also getting another error when I tried an example given in phpmailer docs @ examples/test_smtp_gmail_basic.php

SMTP -> ERROR: Failed to connect toserver: php_network_getaddresses:
getaddrinfo failed: No such host is
known. (0) SMTP Error: Could not
connect to SMTP host. There was a
problem sending this mail!

so there must be setting or configuration error. there can't be code error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十年不长 2024-11-17 00:01:04

SMTP 设置了吗?如果是这样,它是否配置为在端口 587 上侦听 smtp..com?如果服务器不是您自己设置的,那么他们侦听 mail..com 的情况并不少见。另外,尝试连接到端口 25,看看是否可以将其配置为侦听默认 smtp 端口。

无论如何,错误消息都非常清楚。主机没有响应您的连接尝试。原因可能是服务器和 PHP 中的配置错误、防火墙问题、路由问题、DNS 问题等。

Is SMTP set up on ? And if so is it configured to listen to smtp..com on port 587? If the server is not set up by yourself it's not uncommon that they listen to mail..com instead. Also, try to connect to port 25 to see if it might be configured to listen to the default smtp port.

The error messages is in any case very clear. The host is not responding to your connection attempt. The reason could be missconfigurations in both the server and in PHP, firewall issues, routing issues, DNS issues etc.

吃素的狼 2024-11-17 00:01:04

希望这对其他人有帮助,因为我正在与同样的错误作斗争。首先我得到了。我收到一条错误消息,指出无法连接()。然后我打开调试,出现了你提到的错误。对我有用的解决方案是将 smtp..com 更改为 IP 地址。

$mail->Host = 'smtp.whateverDomain.com';

调试

$mail->Host = 'theIPaddress';

$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing)
                           // 1 = errors and messages
                           // 2 = messages only

Hopefully this helps someone else out there because I was fighting this same error. First I was getting. I was getting an error that said it couldn't connect(). Then I turned on the debugging and got the error you mentioned. The solution that worked for me was to change the smtp..com to the ip address.

$mail->Host = 'smtp.whateverDomain.com';

to

$mail->Host = 'theIPaddress';

debugging

$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing)
                           // 1 = errors and messages
                           // 2 = messages only
水溶 2024-11-17 00:01:04

我不久前遇到了这个问题,一切都检查得很好,但问题仍然存在。重新启动 httpd.service 解决了这个问题。

I had this problem a while ago, everything checked out just fine but the problem persisted. A reboot of httpd.service solved it.

夜清冷一曲。 2024-11-17 00:01:04

在运行带有 apache webserver 的 docker 容器的计算机重新启动后出现此问题。

Apache 服务器托管的 php 代码在计算机重新启动后停止发送电子邮件。

重新启动 apache docker 容器解决了该问题。

Had this issue after restart of computer where docker container with apache webserver was running.

Apache server hosted php code which stopped sending emails after computer restart.

Restarting apache docker container solved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文