I've been trying to implement SMTP with PHPMailer for about a week now. I'm revising my old mail() php script and am having difficulty even setting up a live test taken right from the example since I keep receiving the same error. I'm currently running a HostGator dedicated server and my MX record (mail server) is through Office 365/Outlook. For some reason, I keep getting the can't connect to network
error as seen in the image below.
My code is below which I took from the github SMTP example. I originally used port 587 with 'tls' authentication but this did not work and after speaking with Microsoft they suggested I do port 25 with no authentication. Still the same error. Can anyone explain to me what i'm doing wrong or suggest a better route of approach? Thanks!
Code:
<?
require(dirname(__FILE__)."/PHPMailerAutoload.php");
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.office365.com';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "jason@***.com";
$mail->Password = "***";
$mail->setFrom('jason@***.com', 'Jason');
$mail->addReplyTo('jason@***.com', 'Jason');
$mail->addAddress('jason@***.com', 'Jason');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML($email_message);
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>