[英]Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host
I'm using PHPMailer
for sending mail with authentication, but i'm getting the following message when i tried to run my sendmessage.php. 我正在使用
PHPMailer
通过身份验证发送邮件,但是当我尝试运行sendmessage.php时收到以下消息。
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.
can anyone please tell me why i'm getting this message...and some solution for this 谁能告诉我为什么我收到此消息...以及对此的一些解决方案
Mycode is as given below Mycode如下
sendmessage.php 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 = "myemailid@gmail.com";
$mail->Password = "myemailpassword";
$mail->SetFrom('myemailid@gmail.com','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>
从WAMP中打开php.ini文件,并验证unes注释。
尝试这个
$mail->Host = "ssl://smtp.gmail.com";
问题可能是您的防火墙阻止了smtp.gmail.com,而是提供了它应该工作的IP地址
74.125.129.108
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.