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

I get the

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

when I try to run the PHP file. Please help me resolve the error. What could be the possible wrong things I've done to get the error and how to resolve this?

ZygD
  • 22,092
  • 39
  • 79
  • 102
Vignesh Anandakumar
  • 167
  • 1
  • 3
  • 12
  • Please search for answers before posting yet another duplicate of this question. – Synchro May 17 '15 at 13:37
  • None of the answers worked in my case. That's why I posted a question asking for any other solutions. – Vignesh Anandakumar May 17 '15 at 15:11
  • I'm impressed that you read [all 877 duplicates](http://stackoverflow.com/search?q=SMTP+connect%28%29+failed) and failed to try or mention anything they suggested. In that case Ariel's suggestion will be no use because you already tried all that. – Synchro May 17 '15 at 15:17

1 Answers1

2

There are many reasons why this can happen, Here is a document that will help you get through them to solve the problem PHPMailer Troubleshooting connection problems

Ariel Henryson
  • 1,316
  • 1
  • 10
  • 13