Codeigniter Sending email via SMTP Gmail

Here I share with you the way; How to send email in Codeigniter Framework via Gmail SMTP feature.

Write this code in your controller:-


public function send_email() {

        $config = array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://',
            'smtp_port' => 465,
            'smtp_user' => '', // gmail Username
            'smtp_pass' => 'YOUR_GMAIL_PASSWORD', // gmail Password
            'mailtype' => 'html', // what type of mail you want to sent. i.e html/plaintext
            'charset' => 'utf-8',
            'wordwrap' => TRUE

        $message = "Hi, This is a test mail using gmail smtp from my PC using CodeIgniter Framework.";

        $this->load->library('email', $config);
        $this->email->from('FROM_EMAIL_ADDRESS'); // in which email address you want to send email.
        $this->email->to('TO_EMAIL_ADDRESS'); // where your mail goes.
        $this->email->subject('Test Email via Gmail SMTP from My PC');
        $success = $this->email->send();

        if ($success) {
            echo 'Waooo.. Email send successfully!!!';
        } else {
            // if email don't send then shows error.