Message was not sent PHPMailer Error: SMTP connect() failed Error

Message was not sent PHPMailer Error: SMTP connect() failed Error

<?php

require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
// or try these settings (worked on XAMPP and WAMP):
// $mail->Port = 587;
// $mail->SMTPSecure = 'tls';


$mail->Username = "vignesh*****@gmail.com";
$mail->Password = "**********";

$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.

$mail->From = "vignesh*******@gmail.com";
$mail->FromName = "vignesh";

$mail->addAddress("vigneshanandakumar@gmail.com","User 1");
/*$mail->addAddress("user.2@gmail.com","User 2");

$mail->addCC("user.3@ymail.com","User 3");
$mail->addBCC("user.4@in.com","User 4");*/

$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

if(!$mail->Send())
    echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
    echo "Message has been sent";
    ?>

我得到

Message was not sent
PHPMailer Error: SMTP connect() failed

当我尝试 运行 PHP 文件时。请帮我解决错误。我为得到错误所做的可能错误的事情是什么以及如何解决这个问题?

发生这种情况的原因有很多,这里有一份文档可以帮助您解决问题PHPMailer Troubleshooting connection problems