简体   繁体   English

无法连接到SMTP服务器

[英]Unable to connect to SMTP server

I have a server with mail support, say example.com . 我有一台具有邮件支持的服务器,例如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 . 我配置了服务器,并通过cpanel添加了MX记录,以便可以通过地址为myaddr@example.com outlook.com接收和发送邮件。 The MX records are got from domains.live.com . MX记录来自domains.live.com

Now I need to send mail programmatically using PHP using SMTP. 现在,我需要使用PHP通过SMTP以编程方式发送邮件。 I tried PHPmailer using the following script. 我使用以下脚本尝试了PHPmailer。 But it is showing the error 但是它显示了错误

Mailer Error: SMTP Connect() failed. 

(But I can send and receive emails via outlook.com using myaddr@example.com) (但是我可以使用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;
}

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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM