title: Codeigniter: Cannot send email Gmail SMTP
body: <p>I have a problem sending email through google mail SMTP, using email library from Codeigniter.</p>
  
  <p>Here is my Controller's code:</p>
  
  <pre><code>&lt;?php
      class User extends CI_Controller{
  
          function __construct(){
              parent::__construct();
              $this-&gt;load-&gt;model('user_model');
          }
  
  function forgot_password($user_id){
              $data = $this-&gt;user_model-&gt;get_user_detail($user_id);
  
              if(count($data) == 0){
                  $response["error"] = TRUE;
                  $response["error_message"] = "No user data was found";
              }else{
                  $response["error"] = FALSE;
                  $pass = $data-&gt;user_password;               
  
                  $ci = get_instance();
                  $ci-&gt;load-&gt;library('email');
                  $config['protocol'] = "smtp";
                  $config['smtp_host'] = "ssl://smtp.gmail.com";
                  $config['smtp_port'] = "465";
                  $config['smtp_timeout']="30"; 
                  $config['smtp_user'] = "username@gmail.com";
                  $config['smtp_pass'] = "*****";
                  $config['charset'] = "utf-8";
                  $config['mailtype'] = "html";
                  $config['newline'] = "\r\n";
  
                  $ci-&gt;email-&gt;initialize($config);
  
                  $ci-&gt;email-&gt;from('username@gmail.com', 'Name');
                  $list = array($user_id);
                  $ci-&gt;email-&gt;to($list);
                  $ci-&gt;email-&gt;subject('Test: Forgot Password');
                  $ci-&gt;email-&gt;message($pass);
                  if ($this-&gt;email-&gt;send()) {
                      echo 'Email sent!';
                  } else {
                      show_error($this-&gt;email-&gt;print_debugger());
                  }
              }
          }   
      } 
  ?&gt;
  </code></pre>
  
  <p>And this is my Model code:</p>
  
  <pre><code>&lt;?php
      class User_model extends CI_Model{
  
  function get_user_detail($user_id){
                  $this-&gt;db-&gt;where("user_id", $user_id);
                  $query = $this-&gt;db-&gt;get('user');
                  return $query-&gt;row();
          }
  }
  ?&gt;
  </code></pre>
  
  <p>I get this kind of error when I use these functions:</p>
  
  <p>A PHP Error was encountered</p>
  
  <p>Severity: Warning</p>
  
  <pre><code>Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
  
  Filename: libraries/Email.php
  
  Line Number: 1959
  
  Backtrace:
  
  File: C:\xampp\htdocs\rest_api\application\controllers\owner.php
  Line: 71
  Function: send
  
  File: C:\xampp\htdocs\rest_api\index.php
  Line: 292
  Function: require_once
  A PHP Error was encountered
  
  Severity: Warning
  
  Message: fsockopen(): Failed to enable crypto
  
  Filename: libraries/Email.php
  
  Line Number: 1959
  
  Backtrace:
  
  File: C:\xampp\htdocs\rest_api\application\controllers\owner.php
  Line: 71
  Function: send
  
  File: C:\xampp\htdocs\rest_api\index.php
  Line: 292
  Function: require_once
  A PHP Error was encountered
  
  Severity: Warning
  
  Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
  
  Filename: libraries/Email.php
  
  Line Number: 1959
  
  Backtrace:
  
  File: C:\xampp\htdocs\rest_api\application\controllers\owner.php
  Line: 71
  Function: send
  
  File: C:\xampp\htdocs\rest_api\index.php
  Line: 292
  Function: require_once
  </code></pre>
  
  <p>Can anyone give me a solution? I appreciate any help :)</p>