How to resolve the error: Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

I'm using codeigniter I created one email function to send email to particular email ID

public function email($email){
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_timeout']=5;
        $config['smtp_port'] = '465';
        $config['smtp_user'] = 'MyEmailID@gmail.com';
        $config['smtp_pass'] = '********************';
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['newline'] = "\r\n";
        $config['wordwrap'] = TRUE;
        $this->load->library('email');
        $this->email->initialize($config);

        $this->email->from('MyEmailID@gmail.com', 'MyEmailID');
        $this->email->to($email);
        $this->email->subject('My Subject');
        $this->email->message('My Message');
        return $this->email->send();
    }

That's working nice in my local machine but when I uploaded that code to hosting server (I'm using Godaddy hosting) I'm getting following error:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

Filename: libraries/Email.php

Line Number: 2020

Backtrace:

File: /home/MyDir/public_html/application/models/BasicModel.php Line: 47 Function: send

File: /home/MyDir/public_html/application/controllers/Login.php Line: 48 Function: email

File: /home/MyDir/public_html/index.php Line: 315 Function: require_once


ANSWERS:


You forgot to add '

change from

 $config['smtp_host'] = 'ssl://smtp.gmail.com';

to

$config['smtp_host'] = 'smtp.gmail.com';

or

Uncomment php_openssl.dll in php.ini



 MORE:


 ? Why i can't receive delivery or read receipt?
 ? Laravel - Sendgrid smtp error "550 Unauthenticated senders not allowed"
 ? Reading data from fsockopen using fgets/fread hangs
 ? Accessing my outlook inbox via php code
 ? Imap select folder in internationalized languages
 ? retrieving image from database
 ? How to check if a textbox is empty VB.Net
 ? Advanced Search vb.net
 ? create a table using distinct values from a column as the column names in a code
 ? How to use marquee progress bar on a form while waiting for Task to complete