简体   繁体   English

PHPMailer 错误:php_network_getaddresses:getaddrinfo 失败:LOCALHOST(XAMPP)中的名称解析暂时失败

[英]PHPMailer Error: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in LOCALHOST(XAMPP)

First of all, I am using XAMPP on Mac OS and the latest PHP mailer and I know that this might be related to DNS issue, but please read.首先,我在 Mac OS 上使用 XAMPP 和最新的 PHP 邮件程序,我知道这可能与 DNS 问题有关,但请阅读。

This is the full error:这是完整的错误:

2021-06-06 09:04:03 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()

2021-06-06 09:04:23 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution [/opt/lampp/htdocs/enfu2020/123abc/srcs/PHPMailer/src/SMTP.php line 388]

2021-06-06 09:04:23 Connection failed. Error #2: stream_socket_client(): Unable to connect to smtp.gmail.com:587 (php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution) [/opt/lampp/htdocs/enfu2020/123abc/srcs/PHPMailer/src/SMTP.php line 388]

2021-06-06 09:04:23 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (0)

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

And heres' the code:继承人的代码:

try {

$mail = new PHPMailer(true);

//Server settings
$mail->isSMTP();                                            //Send using SMTP
$mail->Host = 'smtp.gmail.com';                     //Set the SMTP server to send through
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;                                   //Enable SMTP authentication
$mail->Username = 'anymail@gmail.com';                 // SMTP username
$mail->Password = 'anyPassword';                                //SMTP password
   $mail->SMTPDebug = 3;


//Recipients
$mail->setFrom('anymail@gmail.com', 'My Cool Name');
$mail->AddAddress($email_1, $namatim);     // Add a recipient
$mail->AddAddress($email_2, $namatim);     // Add a recipient
$mail->AddAddress($email_3, $namatim);     // Add a recipient
$mail->addReplyTo('anymail@gmail.com', 'My Cool Name');

//Content
$mail->isHTML(true);                                  //Set email format to HTML
$mail->Subject = 'Verification Success';
$mail->Body    = 'This is a message';

$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

From the troubleshooting page , I can see that this is indicated as a DNS issue.从故障排除页面,我可以看到这被指示为 DNS 问题。 I suspect this is a problem of my XAMPP's DNS.我怀疑这是我的 XAMPP 的 DNS 的问题。

I've tried to do dig +short smtp.gmail.com on my local machine and it works fine BUT when I clicked on Open Terminal button on XAMPP, and tried to run the same command, that command does not work. I've tried to do dig +short smtp.gmail.com on my local machine and it works fine BUT when I clicked on Open Terminal button on XAMPP, and tried to run the same command, that command does not work.

I am wondering what config needs to be changed on my php.ini, or anything really (I've added extensions=openssl, but still the same error I got).我想知道在我的 php.ini 上需要更改哪些配置,或者其他任何东西(我添加了 extensions=openssl,但仍然出现相同的错误)。

I'd really appreciate it if there's anyone out there that has the way to fix this and willing to share it to me as I'm totally clueless right now and been stuck with it for hours.如果有人有办法解决此问题并愿意与我分享,我将非常感激,因为我现在完全一无所知并且被困了几个小时。

Thanks.谢谢。

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

You have to Import PHPMailer classes into the global namespace, and These must be at the top of your script, not inside a function.您必须将 PHPMailer 类导入全局命名空间,并且这些类必须位于脚本的顶部,而不是 function 中。

For use:用来:

$mail = new PHPMailer(true);

You have to use this command inside your parent directory, because your PHPMailer class will be executed from "Vendor" folder.您必须在父目录中使用此命令,因为您的 PHPMailer class 将从“供应商”文件夹执行。

composer dump-autoload

You can check my code:你可以查看我的代码:

https://github.com/mhreza76/php_pondit/blob/main/session_06/public/php-mailer.php https://github.com/mhreza76/php_pondit/blob/main/session_06/public/php-mailer.php

暂无
暂无

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

相关问题 错误:php_network_getaddresses:getaddrinfo 失败:名称解析暂时失败 (0)(drupal 的 Acquia 连接器登录) - Error: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (0) (Acquia Connector login for drupal) Zabbix“fsockopen(): php_network_getaddresses: getaddrinfo 失败:名称解析暂时失败” - Zabbix "fsockopen(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution" fpdf-php_network_getaddresses:getaddrinfo失败:名称解析暂时失败 - fpdf - php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution file() [function.file]: php_network_getaddresses: getaddrinfo failed: 名称解析暂时失败 - file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution Docker + Laravel 问题 [SQLSTATE[HY000] [2002] php.network_getaddresses: getaddrinfo failed: 名称解析暂时失败] - Docker + Laravel issue [SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution] PHPMailer错误php_network_getaddresses:getaddrinfo失败:名称或服务未知 - PHPMailer error php_network_getaddresses: getaddrinfo failed: Name or service not known 错误:0-php_network_getaddresses:getaddrinfo失败:名称或服务未知 - ERROR: 0 - php_network_getaddresses: getaddrinfo failed: Name or service not known PHPMailer:无法连接到服务器:php_network_getaddresses:getaddrinfo失败 - PHPMailer: Failed to connect to server: php_network_getaddresses: getaddrinfo failed Localhost php_network_getaddresses:getaddrinfo failed:没有这样的主机 - Localhost php_network_getaddresses: getaddrinfo failed: No such host is known 停止此错误ftp_connect():php_network_getaddresses:getaddrinfo失败:临时failu - stop this error ftp_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM