我收到以下错误:SMTP -> 错误: 无法连接到服务器: 连接超时 (110)以下发件人地址失败:test@gmail.com:在未连接的情况下调用 Mail()
我的代码中有什么问题或任何其他问题?
我的openssl也启用了
我正在做以下编码:
<?php
include("securimage/securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == true) {
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body="Name : ".$_POST['name']."<br>";
$body .="Subject : ".$_POST['subject']."<br>";
$body .="Phone : ".$_POST['phone']."<br>";
$body .="Email : ".$_POST['email']."<br>";
$body .=$_POST['comment']."<br>";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host= "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "contactus@gmail.com";
$mail->Password = "contactus";
$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->AddReplyTo($_POST['email']);
$mail->Subject = "Contact Us";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress('niyati@ngplweb.com', 'Niyati');
if(!$mail->Send())
{
setcookie("msg","Error.",time()+5);
header("location:contactus.php");
}
else
{
setcookie("msg","Thank you.We will get back to you soon......",time()+5);
header("location:contactus.php");
}
}
else
{
setcookie("msg","Incorrect Captcha.",time()+5);
header("location:contactus.php");
}
?>
您的密码分配不正确。这可能是您的连接不起作用的原因。
mail->Password = "contactus";
^---
应改为:
$mail->Password = "contactus";
"SMTP -> 错误:无法连接到服务器:连接超时 (110) 以下发件人地址失败:test@gmail.com:未连接而调用 Mail() "
这是因为
$mail->Username = "contactus@gmail.com";
$mail->Password = "contactus";
不是有效的。 尝试使用一些有效的用户名和密码,我认为一切都会好起来的。通过有效,我的意思是真实"gmail ID"的真实用户名和密码。