1

I am having DNS problems running PHPMailer accessing smtp.office365.com on a new cPanel shared hosting plan with register365.com.

My code has worked for years on an older shared hosting plan with the same provider. And it works fine on a test Windows IIS system and a shared hosting plan with another provider. So the problem is unique to register365.com

I am getting a connection error after 300 secs: Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

The standard troubleshooter info in PHPMailer led me to to suspect DNS. So I contacted the provider register365.com and that told me:

Thank you for getting in touch with us about DNS.

Firstly our nameservers are non recursive so they will only return results for domains that are hosted on them so if you try and query smtp.office365.com on our nameservers this is not going to work as its not hosted with us. So if your phpmail script is querying our servers to find this address it wont work and will bring back the error you are seeing.

You will need to set your PHP script to query a general DNS such as googles and this will resolve the issue.

Unfortunately there is nothing we can do in this situation to resolve the issue.

First, does their response make sense? If it does, how can I proceed? So, I would like to be able to either force PHPMailer to use say, Google's 8.8.8.8 DNS server when it tries to resolve smtp.office365.com for initial connection OR somehow force PHP itself to change its default DNS servers. I don't want to hard-code an IP address into the $mail->Host field as Microsoft probably will change them over time.

I am looking for advice on how to proceed. (You may say "use a different Hosting provider" but for various financial I can't!)

<!DOCTYPE html>
<html>
<html lang="en">
<meta charset="utf-8" />
<title>Test Office365 in  Microsoft from Register365.com</title>
<link rel="stylesheet" href="/styles/trekkersfluid.css" type ="text/css" />
</head>

<body class="blank">
<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    require('../PHPMailer/PHPMailerAutoload.php');
    $mail = new PHPMailer;
    $mail->LE = "\r\n";
    $mail->CharSet = 'UTF-8';
    $mail->SMTPDebug = 4;                                   
    $mail->Debugoutput = 'html';
    $mail->isSMTP();
    $mail->Host = "smtp.office365.com";                         // Specify main Office 365 SMTP server
    $mail->SMTPAuth = true;                                 // Enable SMTP authentication
    $mail->Username = 'trekkersend@trekkers.ie';            // SMTP username
    $mail->Password = 'mypassword';                          // SMTP password 
    $mail->SMTPSecure = 'tls';                              // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                      // TCP port to connect to. TLS = 587 SSL = 465
    

    //Set the FROM address
    $FromName = "Joe Murray";
    $mail->setFrom("trekkersend@trekkers.ie"); 

    $mail->addReplyTo("rubbish@jma.ie", "Rubbish Name");
    $mail->addAddress("joseph@jma.ie", "Joseph Murray");
    
    $mail->WordWrap = 70;                                 // Set word wrap to 70 characters

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = "Testing Microsoft Exchange Online Service";
    $mail->Body    = "This is a test";
        
    if(!$mail->send()) {
        echo '<p class="error_msg">Message could not be sent.</p>';
        echo '<p class="error_msg">Mailer Error: ' . $mail->ErrorInfo."</p>";
        exit();
    } else {
        echo '<p class="green">'."Email sent</p>";

    }
     
    ?>
Community
  • 1
  • 1
Joe Murray
  • 11
  • 3

1 Answers1

1

To validate your provider's statement, you could try resolving names other than smtp.office365.com, e.g. google.com. Then you will know for sure whether your provider's DNS server really is non-recursive. I must say, though, that it sounds very strange to me that the physical or virtual machine on which your webhost is running is not configured to use a DNS server that is actually useful.


As a workaround, I would suggest using Google's public DNS-over-HTTP API to query their DNS servers (8.8.8.8 and 8.8.4.4):

https://dns.google.com/resolve?name=smtp.office365.com

But ironically, you are facing the same problem here, which is that you can't resolve dns.google.com.


The only other solution I can see at the moment is to directly query a public DNS server (like 8.8.8.8) via TCP or UDP.

If your hoster provides access to a shell, you can use a tool like nslookup (see this SU question for details).

If you don't have access to a shell, this SO question might prove helpful in order to resolve names with PHP.

Community
  • 1
  • 1
paolo
  • 2,528
  • 3
  • 17
  • 25