0

I am trying to send email using SMTP in CodeIgniter but it is not working. The code is as follows:

public function sendMail(){
    $config = array(
        'protocol'=>'smtp',
        'smtp_host'=>'ssl://smtp.gmail.com',
        'smtp_port'=>465,
        'smtp_user'=>'********@gmail.com',
        'smtp_pass'=>'*********',
        'mailpath'=> "/usr/sbin/sendmail",
        'mailtype'=>'html',
        'charset'   => 'utf-8',
        'send_multipart'=>FALSE
    );

    $this->load->library('email',$config);
    $this->email->initialize($config);
    $this->email->set_newline("\r\n");
    $this->load->library('encrypt',$config);

    $this->email->from('******@gmail.com');
    $this->email->to('******@gmail.com');
    $this->email->cc('******@gmail.com');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');

    if($this->email->send()){
        echo "Email sent success";
    }else{
        show_error($this->email->print_debugger());
    }
}

I tried almost everything I found in the internet especially previous stack questions, but nothing seems to work. I am getting the usual error.

Severity: Warning Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (No connection could be made because the target machine actively refused it. )

Filename: libraries/Email.php Line Number: 2023 The following SMTP error was encountered: 10061 No connection could be made because the target machine actively refused it. Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Deepa_Tmg
  • 1
  • 1
  • 5

1 Answers1

0

things look correct, can you verify your php_openssl.dll is open, you can verify by using function

phpinfo()

if you find false, then uncomment the line

php_openssl.dll in php.ini

hope this work.

M Usman Nadeem
  • 415
  • 2
  • 13