无法连接到 SMTP 服务器

Unable to connect to SMTP server(无法连接到 SMTP 服务器)
本文介绍了无法连接到 SMTP 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a server with mail support, say example.com. I configured the server and added MX records via cpanel, so that I can receive and send mails via outlook.com with address myaddr@example.com. The MX records are got from domains.live.com.

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

Now I need to send mail programmatically using PHP using SMTP. I tried PHPmailer using the following script. But it is showing the error

Mailer Error: SMTP Connect() failed. 

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

(But I can send and receive emails via outlook.com using myaddr@example.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;
}

我该如何解决这个问题.

How can I resolve the issue.

推荐答案

最后我只是通过替换下面的一些设置解决了这个问题,它工作了:).

Finally I just solved the issue by replacing some of the settings as below and it worked :).

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

这篇关于无法连接到 SMTP 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)