PHPMailer error php_network_getaddresses: getaddrinfo failed: Name or service not known

Viewed 2733

i create code for send email using php mailer and its work in localhost but when i run on live server show error bellow :

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

sendmail php code :

<?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;
}

now im running in ubuntu server 12.04 LTS, is there any misconfiguration in my server?

1 Answers

The answer is in the error message:

php_network_getaddresses: getaddrinfo failed: Name or service not known

This means one of two things:

  1. mail.domain.co.id is the wrong name for your mail server
  2. Your DNS service isn't working

This has nothing to do with your script, and everything to do with either your settings or your server's network.

Related