Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

php - SMTP ERROR: Failed to connect to server: Connection timed out (110) with PHPMailer and Outlook SMTP

I am getting SMTP Error with PHP Mailer and Outlook SMTP. I am confused here because it is working fine on localhost with Port number 25 but It is not working on Hosting Server, I have tried all ports with SSL & TLS.

Error : SMTP ERROR: Failed to connect to server: Connection timed out (110)



My Code:

<?php

include("PHPMailer.php"); 

error_reporting(E_ALL);
ini_set('display_errors', '1');

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.live.com";
$mail->SMTPDebug = 2;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->Priority    = 1;
$mail->CharSet     = 'UTF-8';
$mail->ContentType = 'text/html; charset=utf-8
';

$mail->From = "[email protected]";
$mail->FromName = $name;
$mail->AddAddress("[email protected]");

$mail->IsHTML(true);

$mail->Subject = "You got Message from Website";
$mail->Body = "testing";

if(!$mail->Send())
{
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
    echo 'success';
}

?>


Please help me to solve this issue. I have Shared Linux Hosting.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had a similar problem, and it turned out my host (Bluehost) blocked outgoing connections on port 465. I will post the solution here in the hope that helps you. But I'm not expert enough to know if it's the same problem or not.

I found a wonderful how-to which fixed it for me:

  1. In your cPanel DNS Zone editor, find the MX (Mail Exchanger) section, and select 'remote mail exchanger'.
  2. In the cPanel email accounts section, create the appropriate email address (don't skip this)
  3. Don't use "smtp.live.com" as your smtp host. Use the smtp host of your Shared Linux Hosting smtp. I don't know how you will get yours. Mine is boxXXXX.bluehost.com.
  4. Set your username and password to be the same as the email account you just set-up in cPanel.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...