PHPMailer 错误 php_network_getaddresses:getaddrinfo 失败:名称或服务未知
PHPMailer error php_network_getaddresses: getaddrinfo failed: Name or service not known
我使用 php 邮件程序创建用于发送电子邮件的代码及其在本地主机中的工作,但是当我 运行 在实时服务器上显示错误时:
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 服务不工作
这与您的脚本无关,与您的设置或服务器网络无关。
我使用 php 邮件程序创建用于发送电子邮件的代码及其在本地主机中的工作,但是当我 运行 在实时服务器上显示错误时:
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 服务不工作
这与您的脚本无关,与您的设置或服务器网络无关。