title: [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )]
body: <p>I have been troubleshooting this issue for the last two months and have gotten no results on how to fix this. I am using PHP 5.6.3 with PEAR 1.10.1, the emailing pages in question worked fine with our 3-party emailing software on our local server only designed to use port 25 for SMTP. Now the PHP pages do reference an XML template that contains all the host, password, and username information. I want to switch to using google email servers with SSL. I implemented the changes provided by my email administrator and change the MX records accordingly. It was functioning properly for two weeks. After that I was getting the following error </p>
  
  <p><strong><em>"Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )]"</em></strong>.</p>
  
  <p>I have changed the code several times, I removed the ssl://, I have changed the protocol type to TLS with the port number 587, etc. Nothing was working! I reached out to the contractor to construct a simple hard-coded page that just said hello world using the gmail server configuration. He refused and made myself make a simple php page, mind you I had zero background in PHP programming until now, so on a side note entirely happy that this was thrown my way, but regardless I did complete the task. I have a page that sends a simple message, using the smtp server with the account desired using the PHPMailer library. (See the code below)</p>
  
  <pre><code> &lt;?php  
  
  
  require_once 'C:\Webpage\PHPMailer-5.2-stable/PHPMailerAutoload.php';
  
  $mail = new PHPMailer();
  $mail-&gt;isSMTP();
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;SMTPDebug = SMTP::DEBUG_SERVER;
  $mail-&gt;SMTPDebug   = 4; // 2 to enable SMTP debug information
  
  
  $mail-&gt;Host = 'smtp.gmail.com';
  $mail-&gt;Username = 'username@gmail.com';
  $mail-&gt;Password = 'XXXXXXXXXXXXXXXXXXX';
  $mail-&gt;SMTPSecure ='ssl';
  $mail-&gt;Port = 465;
  
  /*$mail-&gt;SMTPOptions = array(
      'ssl' =&gt; array(
          'verify_peer' =&gt; false,
          'verify_peer_name' =&gt; false,
          //'allow_self_signed' =&gt; true
      )
  );*/
  
  $mail-&gt;From = 'XXXXt@abc.com';
  $mail-&gt;FromName = 'Example';
  $mail-&gt;addReplyTo('testing@abc.com','Example');
  $mail-&gt;AddAddress('user1@xyz.com', 'John Doe');
  
  
  $mail-&gt;Subject = 'Hello World';
  $mail-&gt;Body ='A test email!';
  $mail-&gt;AltBody = 'A test email!';
  
  
  
   if(!$mail-&gt;Send()) {
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
   } else {
      echo "Message has been sent";
   }
          ?&gt;
  </code></pre>
  
  <p>Now I know this is not using PEAR, but from this I found out some interesting information that I think is related. The code only works if the line with </p>
  
  <pre><code> $mail-&gt;SMTPOptions = array(
          'ssl' =&gt; array(
              'verify_peer' =&gt; false,
              'verify_peer_name' =&gt; false,
              //'allow_self_signed' =&gt; true
          )
  );
  </code></pre>
  
  <p>is not commented out it works, but when it is commented out, I receive an error regarding this. </p>
  
  <pre><code>Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [C:\Webpage\PHPMailer-5.2-stable\class.smtp.php line 299]
  </code></pre>
  
  <p>So I googled this error and was lead to the php.ini file to change the openssl.cafile and the openssl.capath values. I entered in the download CA certificates and entered the correct pathway for the values, but still it is not working. Am I placing these in the wrong area? Or is there an easier way to fix this issue using the PEAR library? Please any help on this subject will be appreciated!:) </p>
  
  <p>UPDATE(02/20/2018):</p>
  
  <p>I have downloaded the bundle and set the pathway to it's correct location,<code>curl.cainfo ="C:\OpenSSL-Win64\bin\PEM\cacert.pem"</code>,<code>openssl.cafile="C:\OpenSSL-Win64\bin\PEM\cacert.pem"</code>. I still am getting the error I ran the following check of the ssl locations to see if it was using the <code>php.ini</code> file and got the following.</p>
  
  <pre><code>    &lt;?php
   error_reporting(E_ALL);
  
  print "\nIf you've got this far without errors then problem is with your SSL config\n";
   $calocns=openssl_get_cert_locations();
   if (count($calocns)) {
       print "Check you've got your cacerts deployed in one of the following locations\n";
       foreach ($calocns as $k=&gt;$v) print "$k = $v\n";
   } else {
       print "You've not configured your openssl installation on this host\n";
   }
  $calocns=openssl_get_cert_locations();
  //var_dump(openssl_get_cert_locations());
  
  
  ?&gt;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>    If you've got this far without errors then problem is with your SSL config Check you've got your cacerts deployed in one of the following locations default_cert_file = f:\repo\winlibs_openssl_vc11_x86/cert.pem default_cert_file_env = SSL_CERT_FILE 
      default_cert_dir = f:\repo\winlibs_openssl_vc11_x86/certs 
      default_cert_dir_env = SSL_CERT_DIR 
      default_private_dir = f:\repo\winlibs_openssl_vc11_x86/private
   default_default_cert_area = f:\repo\winlibs_openssl_vc11_x86 
      ini_cafile = 
      ini_capath = 
  </code></pre>
  
  <p>I seem to be doing this wrong or need to know how to change the locations because those locations are not existent on my computer and I don't understand how it goes to those by default when I changed the pathway in the configuration file itself. Any thoughts?</p>