简体   繁体   English

SMTP connect()失败的PHP邮件程序

[英]SMTP connect() failed PHP mailer

I'm trying to send an email from my hotmail account using PHPMailer. 我正在尝试使用PHPMailer从我的hotmail帐户发送电子邮件。 It's working fine from my PC but when I try it on another PC I get this error message: 从我的PC可以正常工作,但是当我在另一台PC上尝试时,出现以下错误消息:

2015-04-23 17:31:18 CLIENT -> SERVER: EHLO localhost 2015-04-23 17:31:18客户端->服务器:EHLO本地主机
2015-04-23 17:31:18 CLIENT -> SERVER: QUIT 2015-04-23 17:31:18客户端->服务器:退出
2015-04-23 17:31:18 SMTP connect() failed. 2015-04-23 17:31:18 SMTP connect()失败。 Mailer Error 邮件错误

Here's my code: 这是我的代码:

<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
    $mail = new PHPMailer();
    $mail->SMTPSecure = 'SSL';
    $mail->Username = "b1sakher@hotmail.fr";
    $mail->Password = "rerered";
    $mail->AddAddress("b1sakher@hotmail.fr");
    $mail->FromName = "My Name";
    $mail->Subject = "My Subject";
    $mail->Body = "My Body";
    $mail->Host = "smtp.live.com";
    $mail->Port = 587;
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->From = $mail->Username;
  if(!$mail->Send())
    {
     echo "Mailer Error";
    }
    else
     {
    echo "Message has been sent";
    }
?>

Firstly you should add 'Debugging Mode' to your code, this will tell you where you are going wrong. 首先,您应该在代码中添加“调试模式”,这将告诉您哪里出了问题。

$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant

I had a similar issue, but found out it was the CFS Firewall in Cpanel/WHM blocking the port. 我遇到了类似的问题,但发现它是Cpanel / WHM中的CFS防火墙阻止了该端口。

  1. Login into WHM. 登录到WHM。
  2. Go to ConfigServer Security & Firewall inside plugins option. 转到“插件内部的ConfigServer安全性和防火墙”选项。
  3. Click on Firewall configuration. 单击防火墙配置。
  4. Filter by SMTP Settings. 按SMTP设置过滤。
  5. Look for SMTP_ALLOWUSER option and add the Cpanel account username separated by coma. 查找SMTP_ALLOWUSER选项,然后添加以逗号分隔的Cpanel帐户用户名。
  6. Restart the firewall. 重新启动防火墙。

If you don't have access to WHM ask your hosting provider. 如果您无权访问WHM,请询问您的托管服务提供商。

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

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