views:

300

answers:

2

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,

<?php
    require_once('../class.phpmailer.php');
    //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   = "[email protected]";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddReplyTo('[email protected]', 'First Last');
      $mail->AddAddress('[email protected]', 'John Doe');
      $mail->SetFrom('[email protected]', 'First Last');
      $mail->AddReplyTo('[email protected]', '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->MsgHTML(file_get_contents('contents.html'));
      $mail->AddAttachment('images/phpmailer.gif');      // attachment
      $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
      $mail->Send();
      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!
    }
    ?>
A: 

Well, the error message says it all:

Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

It means that the PHP version is not equipped with the necessary libraries to communicate with the mail server (or any other server for that matter) through SSL.

If you don't have root access to your server, this is probably an issue for your server administrator / provider.

From a similar discussion in a forum, a possible solution that sounds quite realistic:

My guess is that either mod_ssl is not installed for apache or it is installed but the configuration lines for mod_ssl are commented out in httpd.conf (like it was on suse9 for me). apxs will only enable ssl functions in php if mod_ssl is up and running

So check mod_ssl is available + enabled in apache then try recompiling php with

./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-ssl

Pekka
I uncommented the "LoadModule ssl_module modules/mod_ssl.so", and restarted but no change, i am still getting error.how can I check if mod_ssl is available??
San
I think you would also have to recompile PHP with `--enable-ssl`. Check out `phoinfo();` first to see how PHP is compiled.
Pekka
@San: You also need to have support enabled in php i think as was mentioned upstream by Waleed. Note he gave windows specific instruction in reference to the extension it should be an `.so` on a *nix box.
prodigitalson
+3  A: 

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:

http://us2.php.net/manual/en/openssl.installation.php

Waleed Al-Balooshi
wow..uncommenting extension = PHP_openssl.dll worked.I dont understand why was it commented.This is my first day of php coding, I have a lot to learn
San
Certain features are commented by default. If you look through the php.ini you will find several of them in there. The reason for this I am not sure of. I am happy you got it working though.
Waleed Al-Balooshi
+1 Good call Waleed.
Pekka