Unable to send email through gmail using PHPMailer_v5.1

I am trying to send email through gmail using PHPMailer_V5.1.

Getting the following error,

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (41961176) SMTP Error: Could not connect to SMTP host.

The following is the code which came with the PHPMailer download, I just modified the required fields,

    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
      $mail->Host       = "mail.yourdomain.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
      $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
      $mail->Username   = "santosh1984naidu@gmail.com";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddAddress('santosh1984naidu@gmail.com', 'John Doe');
      $mail->SetFrom('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
      $mail->AddAttachment('images/phpmailer.gif');      // attachment
      $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
      echo "Message Sent OK</p>\n";
    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!


Based on the error it seems that SSL is not enabled in PHP. Off the top of my head I believe that you need to uncomment

extension = PHP_openssl.dll

in your php.ini file

Following should help you install SSL if it is already setup on your system:


Need Your Help

OCaml variant types: confusing the compiler

types ocaml

I'm trying to understand variants in OCaml (while this isn't homework, the assignment is taken from my friend's old assignment, so please don't give corrected code).

WPF MVVM Changes to DataContext not saved to DB

wpf mvvm

I Have a data context containing a list of employees.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.