消息未发送PHPMailer错误:SMTP connect()失败错误

时间:2015-05-17 11:02:05

标签: php phpmailer

<?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错误:SMTP connect()失败

当我尝试运行PHP文件时。请帮我解决错误。我为解决这个错误以及如何解决这个问题可能会出现什么错误?

1 个答案:

答案 0 :(得分:2)

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