PHPMailer错误:SMTP connect() failed错误


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";
    ?>

我得到

消息未发送
PHPMailer Error: SMTP connect() failed

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

发生这种情况的原因有很多,这里有一个文档将帮助您解决问题PHPMailer故障排除连接问题