2016-05-30 217 views
0

当我发送的电子邮件从服务器然后它给我的两个错误 -无法连接到SMTP主机。消息无法发送

SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

我发现很多暗示对堆栈溢出另一个答案,但不起作用。我试了端口号465/587/65。即使下面的代码适用于我的本地系统如果我设置端口587.但在服务器中,它不起作用。

require('class.phpmailer.php'); 
require('class.smtp.php'); 

$mail = new PHPMailer(); 

$mail->IsSMTP();  
$mail->SMTPSecure = "ssl"; 
$mail->SMTPAuth = true; 
$mail->Host = "smtp.gmail.com"; 
$mail->Username = "FromEmailId"; 
$mail->Password = "Password"; 
$mail->Port = 465; 
$mail->From = "FromEmailId"; 
$mail->AddAddress("ToEmail");  
$mail->IsHTML(true);         
$mail->Subject = "Here is the subject"; 
$mail->Body = "This is the HTML message body <b>in bold!</b>"; 

if(!$mail->Send()) 
{ 
    echo "Message could not be sent. <p>"; 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    exit; 
} 
echo "Message has been sent"; 
+0

我认为这是服务器端错误 –

+0

@Yogesh。感谢回复。但是我怎么能解决它。? –

+0

亲爱的我也面临这个问题,但不是任何解决方案 –

回答

0

Gmail帮助的:在调试模式下

Still can't send mail?

If you tried configuring your SMTP server on port 465 (with SSL/TLS) and port 587 (with STARTTLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL/TLS).

+0

感谢您的回复。我试过465/587/25但没有人工作。 –

+0

尝试在服务器中连接smtp链接,https://support.google.com/mail/answer/78775最后回答 –

1

尝试PHPMailer的检查错误

$mail->SMTPDebug = 3;  // Enable verbose debug output 
+0

请您详细说明您的答案,并添加关于您提供的解决方案的更多描述。 – abarisone

+0

在发布的答案中,这是唯一一个正确的方向,但它应该是一个评论。 – Synchro

+0

@Synchro同意你的看法。这个简单的代码可以帮助你调试phpmailer。它基本上给出了详细的错误来帮助你追踪错误或错误。 –

1

首先登出了Gmail帐户

然后打开这个网址 use this yrl

enter image description here

点击继续按钮

下一页 改变港口和SMTPsecure

$mail->SMTPSecure = "tls"; 
$mail->Port = 587; 
+0

感谢您回复Yogesh。我和我的朋友讨论过,他告诉我们,需要对godaddy服务器(配置电子邮件)进行一些设置。这就是为什么它不工作。我尝试通过更改SMTPSecure和端口,但它不起作用。 –

+0

@PuneetChawla尝试这个过程一次...因为在我的情况下,我得到同样的问题,但使用这个过程我发送邮件没有任何错误 –

+0

好的yogesh。我会尽快尝试,并会让你确定地知道。 –

0

这个问题没有做一个基本的搜索,错过了后面提到的信息的重要部分评论:OP正在使用GoDaddy。 GoDaddy众所周知阻止出站SMTP,所以任何有关切换端口号或安全协议的建议都无济于事。您需要阅读other questions on GoDaddy's mail handling,并阅读其支持文档,这会推动您使用GoDaddy邮件服务器(使用securehosting域)或通过本地主机作为中继站。所有这些也在PHPMailer troubleshooting guide中涵盖。

未来,在发布之前进行搜索,按照SO guidelines

相关问题