CodeIgniter’s robust Email Class supports the following features:

> Multiple Protocols: Mail, Sendmail, and SMTP

> TLS and SSL Encryption for SMTP

> Multiple recipients

> CC and BCCs

> HTML or Plaintext email

> Attachments

> Word wrapping

> Priorities

> BCC Batch Mode and enabling large email lists to be broken into small BCC batches.

> Email Debugging tools

How to send email in CodeIgniter

Create a view file send_email.php and save the below code it in application/views/send_email.php.

<!DOCTYPE html>
<title>Send Mail</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>

    <div class="container mt-4">
        <div class="row">
            <div class="col-lg-6">
                <form action="<?= base_url('demo/send_mail') ?>" method="post">
                    <input type="email" name="to" class="form-control" placeholder="Enter Receiver email">
                    <input type="text" name="subject" placeholder="Enter Subject" class="form-control">
                    <textarea rows="6" name="message" placeholder="Enter your message here" class="form-control"></textarea>
                    <input type="submit" value="Send Email" class="form-control">

Create a controller file Demo.php and save it in application/controller/Demo.php.

defined('BASEPATH') OR exit('No direct script access allowed');

class Demo extends CI_Controller {
    function index(){
    function send_mail(){
        $config['protocol'] = 'smtp';
                $config['smtp_host'] = 'ssl://';
                $config['smtp_port'] = '465';
                $config['smtp_timeout'] = '7';
                $config['smtp_user'] = 'Enter your email';
                $config['smtp_pass'] = 'Enter your email password';
                $config['charset'] = 'utf-8';
                $config['wordwrap'] = TRUE;
                $config['newline'] = "\r\n";
                $config['mailtype'] = 'html'; // or html
                $config['validation'] = TRUE; // bool whether to validate email or not

        $to = $this->input->post("to");
        $subject = $this->input->post("subject");
        $message = $this->input->post("message");
        $this->email->from('Enter your email', 'Hello'); 

After Login to your google account and click on the link : Less secure app access

After you Allow less secure apps:ON

Let us execute this example by the following URL in the browser. This URL may be different based on your website.