无法连接到SMTP服务器 [英] Unable to connect to SMTP server

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

问题描述

我有一台支持邮件的服务器,例如example.com.我配置了服务器并通过cpanel添加了MX记录,以便可以通过地址为myaddr@example.comoutlook.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;
}

如何解决该问题.

推荐答案

最后,我只是通过替换下面的一些设置解决了该问题,并且起作用了:).

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服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆