[英]SMTP -> ERROR: Failed to connect to server: (0) in PHP malier
Following is my php email code and it works fine still today. 以下是我的php电子邮件代码,今天仍然可以正常使用。
require_once('_lib/class.phpmailer.php');
include 'func/db_connect.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
function supervisorMail(){
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "*****@gmail.com";
$mail->Password = "*****";
$mail->SetFrom("****@gmail.com", "Employee Leave Management System");
}
But now it does not work without any changing of code and it makes following error. 但是现在,如果不更改任何代码,它将无法正常工作,并且会导致以下错误。
SMTP -> ERROR: Failed to connect to server: (0) SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
I could not able to find the solution. 我找不到解决方案。 How can I fixed this. 我该如何解决。
try this it will be work 试试这个会起作用
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "*******@gmail.com";
$mail->Password = "*******";
you have to change in gmail.In Account permissions section, find Access for less secure apps and enable it. 您必须在gmail中进行更改。在“帐户权限”部分中,找到安全性较低的应用的访问权限并将其启用。
I think you should try by changing the host like this : 我认为您应该尝试通过更改主机来像这样:
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
And also set the other paramters like this : 并像这样设置其他参数:
$mail->SetFrom('contact@example.com', 'User');
$mail->AddReplyTo("example@gmail.com', 'Name Here");
$mail->Subject = "Contact us Email";
$mail->MsgHTML($body);
$address = "user@example.com";
$mail->AddAddress($address, "new user");
if(!$mail->Send()) {
echo "Error in Sending email: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
In my case it was a lack of SSL support in PHP which gave this error. 在我的情况下,PHP中缺少SSL支持导致了此错误。
So I enabled extension=php_openssl.dll 所以我启用了extension = php_openssl.dll
$mail->SMTPDebug = 1; $ mail-> SMTPDebug = 1; also hinted towards this solution. 也暗示了这种解决方案。
提供$ mail-> SMTPDebug = 1 itz工作[1]: http ://i.stack.imgur.com/ZEpjv.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.