gpt4 book ai didi

PHPMailer 错误 php_network_getaddresses : getaddrinfo failed: Name or service not known

转载 作者:行者123 更新时间:2023-12-04 18:31:19 24 4
gpt4 key购买 nike

我使用 php mailer 创建用于发送电子邮件的代码,它在 localhost 中工作,但是当我在实时服务器上运行时,显示错误如下:

2020-11-16 07:45:03 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) 2020-11-16 07:45:03 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


发送邮件 php 代码:
<?php
/**
* This example shows sending a message using a local sendmail binary.
*/

require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'mail.domain.co.id';
$mail->SMTPAuth = true;
$mail->Username = 'notreply@domain.co.id';
$mail->Password = 'XXXXXXXXXX';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('notreply@domain.co.id');
$mail->addReplyTo('notreply@domain.co.id');
$mail->addAddress('myemail@domain.co.id');

$mail->Subject = 'Test Email via Mailtrap SMTP using PHPMailer';
$mail->isHTML(true);
$mailContent = "<h1>Send HTML Email using SMTP in PHP</h1>
<p>This is a test email I'm sending using SMTP mail server with PHPMailer.</p>";
$mail->Body = $mailContent;
if($mail->send()){
echo 'Message has been sent';
}else{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
现在我在 ubuntu 服务器 12.04 LTS 中运行,我的服务器中是否有任何错误配置?

最佳答案

答案在错误消息中:

php_network_getaddresses: getaddrinfo failed: Name or service not known
这意味着两件事之一:
  • mail.domain.co.id是您的邮件服务器的错误名称
  • 您的 DNS 服务不工作

  • 这与您的脚本无关,与您的设置或服务器网络有关。

    关于PHPMailer 错误 php_network_getaddresses : getaddrinfo failed: Name or service not known,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64854303/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com