[英]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.