我有一個DNS問題運行PHPMailer訪問smtp.office365.com在一個新的cPanel共享主機計劃register365.com。php PHPMailer共享主機覆蓋默認DNS服務器
我的代碼已經在同一提供程序的舊共享主機計劃上工作了多年。它可以在測試的Windows IIS系統和另一個提供商的共享託管計劃中正常工作。所以這個問題是唯一的register365.com
我在300秒後出現連接錯誤: 連接失敗。錯誤#2:stream_socket_client():php_network_getaddresses:getaddrinfo失敗:名稱解析中的臨時失敗
PHPMailer中的標準疑難解答信息導致我懷疑DNS。所以我聯繫了提供商register365.com,並告訴我:
感謝您與我們聯繫有關DNS。
首先,我們的域名服務器是非遞歸的,所以他們只會返回託管在他們的域名的結果,所以如果您嘗試在我們的域名服務器上查詢smtp.office365.com,這將無法正常工作,因爲它不與我們託管。所以如果你的phpmail腳本查詢我們的服務器來找到這個地址,它不會工作,並會帶回你看到的錯誤。
您將需要設置您的PHP腳本來查詢一般的DNS,例如Google,這將解決問題。
不幸的是,在這種情況下我們無能爲力來解決這個問題。
首先,他們的反應是否有意義? 如果有,我該怎麼辦? 因此,我希望能夠強制PHPMailer在嘗試解析smtp.office365.com進行初始連接時使用Google的8.8.8.8 DNS服務器,或者以某種方式強制PHP本身更改其默認DNS服務器。我不想將IP地址硬編碼到$ mail-> Host字段中,因爲Microsoft可能會隨着時間的推移更改它們。
我在尋找關於如何繼續的建議。 (你可能會說「使用不同的託管服務提供商」,但對於各種金融我不能!)
<!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 = '[email protected]'; // 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("[email protected]");
$mail->addReplyTo("[email protected]", "Rubbish Name");
$mail->addAddress("[email protected]", "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>";
}
?>