2014-01-09 151 views
0

我使用PHPMailer发送具有身份验证的邮件,但是当我尝试运行我的sendmessage.php时收到以下消息。无法连接到SMTP主机。邮件错误:SMTP错误:无法连接到SMTP主机

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. 

谁能告诉我为什么我得到这个消息,和这

mycode的一些解决方案如下

sendmessage.php

<html> 
<head> 
<title>PHPMailer - SMTP (Gmail) basic test</title> 
</head> 
<body> 

<?php 

//error_reporting(E_ALL); 
error_reporting(E_STRICT); 

date_default_timezone_set('America/Toronto'); 

require_once('../class.phpmailer.php'); 
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 


$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "myemailpassword"; 
$mail->SetFrom('[email protected]','vgvb'); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress('myfriendemailid'); 
if(!$mail->Send()) 
    { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    } 
    else 
    { 
    echo "Message has been sent"; 
    } 
?> 

</body> 
</html> 
给出
+0

贵启用主机服务器上的端口465进行沟通?有些主机不允许你发送邮件。 –

+0

我们是否有默认情况..........如何检查 – user3159579

+0

您将不得不打电话或通过电子邮件发送您的托管服务提供商。 –

回答

0

试试这个

$mail->Host = "ssl://smtp.gmail.com"; 
+0

响应没有变化...... – user3159579

+0

尝试删除$ mail-> SMTPSecure ='ssl';藏汉 – gbestard

1

打开的php.ini从WAMP文件,并验证openssl.dll是注释。

0

的问题可能是您的防火墙阻止smtp.gmail.com,而不是给IP地址它应该工作

74.125.129.108 
相关问题