无法连接到 SMTP 服务器


Unable to connect to SMTP server

我有一个支持邮件的服务器,比如example.com。我配置了服务器并通过cpanel添加了MX记录,以便我可以通过地址为myaddr@example.comoutlook.com接收和发送邮件。MX 记录是从 domains.live.com 获取

的。

现在我需要使用 PHP 通过 SMTP 以编程方式发送邮件。我使用以下脚本尝试了PHPmailer。但它显示了错误

Mailer Error: SMTP Connect() failed. 

(但我可以使用 myaddr@example.com 通过 outlook.com 发送和接收电子邮件)

$body             = $_POST['message'];
$to = "support@example.org";
$from = 'fromAddress@gmail.com';
$fName = 'first name';
$lName = 'last name';
$subject =  'my subject';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
  //  $body             = eregi_replace("[']",'',$body);
$mail->Host       = "mail.example.org"; // SMTP server example
$mail->SMTPDebug  = 0;           // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;        // enable SMTP authentication
$mail->Port       = 25;          // set the SMTP port for the GMAIL server
$mail->Username   = "myaddr@example.org"; // SMTP account username example
$mail->Password   = "password";
$mail->SetFrom($from, $fName.' '.$lName);
$mail->Subject = $subject;
$mail->AddAddress($to, "Support Team");
$mail->MsgHTML($body);
if(!$mail->Send()) {
     echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

如何解决此问题。

最后,

我只是通过替换下面的一些设置来解决问题,它:)工作。

    $mail->Host       = "smtp-mail.outlook.com"; // SMTP server example
    $mail->Port       = 587;  
    $mail->SMTPSecure = 'tls';