我使用php mailer创建发送电子邮件的代码,并在localhost中工作,但当我在实时服务器上运行时,显示以下错误:
2020-11-16 07:45:03 SMTP错误:无法连接到服务器:php_network_getaddresses:getaddrinfo失败:名称或服务未知(0(2020-11-116 07:45:03SMTP connect((失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting无法发送消息。Mailer错误:SMTP连接((失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
sendmail 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服务不工作
这与您的脚本无关,一切都与您的设置或服务器的网络有关。