Message stream_socket_enable_crypto SSL-TLS already set up for this stream

Message stream socket enable crypto SSL TLS already set up for this stream

Hello guys in this article I will explain to you how to solve this issue from your code. You know the time when you will send a message via SMTP these times this kind of issue will come and your email won’t now work. 

Let’s see how to solve this issue. 

  • $config['mailtype'] = 'html';: Specifies that the email content will be in HTML format.
  • $config['protocol'] = 'smtp';: Sets the email protocol to SMTP.
  • $config['smtp_host'] = 'smtp.hostinger.com';: Defines the SMTP server host (in this case, Hostinger's SMTP server).
  • $config['smtp_user'] = 'your user name';: Specifies the SMTP username for authentication.
  • $config['smtp_pass'] = 'password';: Specifies the SMTP password for authentication.
  • $config['smtp_port'] = 465;: Sets the SMTP server port number.
  • $config['newline'] = "\r\n";: Defines the newline character sequence.
  • $config['wordwrap'] = true;: Enables word-wrapping of the message.
  • $config['smtp_crypto'] = 'ssl';: Specifies the encryption method to use for the SMTP connection (SSL in this case).
  • $config['verify_peer'] = false;: Disables peer verification for SSL/TLS connections.

Example:- 

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
  public function __construct(){
    parent::__construct();   
     $this->load->library('email');
    $config['mailtype'] = 'html';
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'smtp.hostinger.com';
    $config['smtp_user'] = 'user name';
    $config['smtp_pass'] = 'password';
    $config['smtp_port'] = 465;
    $config['newline'] = "\r\n";
    $config['wordwrap'] = true;
    $config['smtp_crypto'] = 'ssl';
    $config['verify_peer'] = false;
    $this->email->initialize($config);
    $this->email->set_newline("\r\n");
}
   public function emailTest(){
    $this->email->set_mailtype("html");
    $this->email->from('xyz@domain', 'Sanatani Coin');
    $this->email->reply_to('xyz@domain');
    $this->email->to('sendmail@gmail.com');
    $this->email->subject('Hello I am test');
    $this->email->message('How can I test email');
    if($this->email->send()){
          echo "Email send successfully done";
       }else{
         echo "Email not send";
        }
    }
}