0

I am struggling in how to send email by using smtp gmail.

This error always happens to me,

[message:protected] => fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)
[string:Exception:private] => 
[code:protected] => 2
[file:protected] => /home/u6676613/public_html/testing/system/libraries/Email.php
[line:protected] => 1689
[trace:Exception:private] => Array

Below is my configuration for sending the email

    $config['protocol']='smtp';  

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

            $config['smtp_port']='465';  
            //$config['smtp_crypto'] = 'ssl';
            $config['smtp_timeout']='30';    
            $config['smtp_user']=$smtp_username;  
            $config['smtp_pass']=$smtp_password;  
            $config['charset']='utf-8';  
            $config['newline']="\r\n";  
            $config['mailtype'] = 'html'; 

                $config['charset']='utf-8';  
                $config['newline']="\r\n";  
                $config['mailtype'] = 'html';
                $this->load->library('email');
                $this->email->initialize($config);


            $this->email->from('do-not-reply@blabla.com');
            $this->email->to($email);
            $this->email->subject('Testing');
            $this->email->message($msg);
                if($this->email->send())
                {


                    $this->success();
                }
                else
                {
                    show_error($this->email->print_debugger());
                }

If i try to uncomment smtp crypto, i got error " fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known"

FYI ssl extension already enabled. Kindly need your help for this matter

My problem is not ssl extension related so i think its not duplicate with another issue

Shandy Kurnia
  • 21
  • 2
  • 8
  • Try removing `ssl://` part from host parameter perhaps and see if it works (also uncomment smtp_crypto then) – p0358 Nov 18 '18 at 21:32
  • uncomment smtp crypto and run in terminal `setsebool httpd_can_network_connect=1` – user969068 Nov 18 '18 at 22:37
  • i've tried uncomment smtp crypto and remove ssl:// still got same error message "fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)" – Shandy Kurnia Nov 19 '18 at 01:10
  • Possible duplicate of [fsockopen(): unable to connect to ssl://smtp.gmail.com:465](https://stackoverflow.com/questions/38203839/fsockopen-unable-to-connect-to-ssl-smtp-gmail-com465) – Twinkle Nov 19 '18 at 04:33
  • what do you mean by duplicate ? If im using another smtp server, it works. but if im using smtp google, i always get this error – Shandy Kurnia Nov 19 '18 at 07:34

2 Answers2

0

use sendinblue email provider, it's very easy to implement and it can track emails properly as well as free also.

Mohit Rathod
  • 1,057
  • 1
  • 19
  • 33
0

Check LESS SECURE APPSon your google account. By turning IT on, IT should work! LESS SECURE APPS

KayaP
  • 59
  • 1
  • 1
  • 5