0

I try to send email on localhost xampp using codeigniter. I modified php.ini and sendemail.ini file in xampp follow the guide. my codeigniter code is follow.

public function send_mail() {

        $config['useragent'] = 'CodeIgniter';
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = '587';
        $config['smtp_user'] = '****@gmail.com';
        $config['smtp_pass'] = '****';
        $config['smtp_timeout'] = 5;
        $config['wordwrap'] = TRUE;
        $config['wrapchars'] = 76;
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['validate'] = FALSE;
        $config['priority'] = 3;
        $config['crlf'] = "\r\n";
        $config['newline'] = "\r\n";
        $config['bcc_batch_mode'] = FALSE;
        $config['bcc_batch_size'] = 200;
        $this->load->library('email', $config);

        $from_email = "csharpdev0423@gmail.com";
        $to_email = $this->input->post('email');
        //Load email library
        $this->load->library('email');
        $this->email->initialize($config);
        //$this->load->library('email', $config);
        $this->email->from($from_email, 'Identification');
        $this->email->to($to_email);
        $this->email->subject('Send Email Codeigniter');
        $this->email->message('The email send using codeigniter library');
        //Send mail
        if($this->email->send())
            $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
        else
            $this->session->set_flashdata("email_sent","You have encountered an error");
        $this->load->view('contact_email_form');
    }
    
    
But it have above error.

A PHP Error was encountered Severity: Warning

Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

Filename: libraries/Email.php

Line Number: 2055

Community
  • 1
  • 1
rharmed
  • 23
  • 7
  • 1
    this is not good idea post valid credentials in you question – Alexander Feb 22 '18 at 08:29
  • Duplicate https://stackoverflow.com/questions/30610387/cant-send-email-with-php-mail-function-on-windows-8/30610643#30610643 – Abdulla Nilam Feb 22 '18 at 08:29
  • roytuts.com/how-to-send-mail-with-xampp-and-mercury32-in-windows/ – user3470953 Feb 22 '18 at 08:36
  • You may need to set up the back end sendmail in xampp https://www.youtube.com/watch?v=TO7MfDcM-Ho –  Feb 22 '18 at 08:55
  • Possible duplicate of [Send email by Email Class in codeigniter with Gmail](https://stackoverflow.com/questions/9564400/send-email-by-email-class-in-codeigniter-with-gmail) – Renati Feb 22 '18 at 09:01

1 Answers1

1

You can changes following email config array.

<?php 
// change hostname
$config['smtp_host'] = 'smtp.gmail.com';

// change stmp port number
$config['smtp_port'] = '465';

// add smtp_crypto
$config['smtp_crypto'] = 'ssl';


// Change charset
$config['charset'] = 'iso-8859-1';

?>

Hope it will help.

NikuNj Rathod
  • 1,663
  • 1
  • 17
  • 26
  • right smtp_crypto must have on localhost and same as the charset have iso-8859-1 because utf-8 not support on localhost for codeigniter email but if you use phpmailer then charset utf-8 works – heySushil Nov 29 '19 at 07:16