Sending an email is not only simple, but you can configure it on the fly or set your preferences in a config file. CodeIgniter provides an Email library for sending.

Step 1: Create the controller file




class Email_controller extends CI_Controller {

    function __construct() {

    public function index() {


    public function send_mail() {
        $from_email = "";
        $to_email = $this->input->post('email');

        //Load email library 

        $this->email->from($from_email, 'Your Name');
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');

        //Send mail 
        if ($this->email->send())
            $this->session->set_flashdata("email_sent", "Email sent successfully.");
            $this->session->set_flashdata("email_sent", "Error in sending Email.");



Step 2: Create the view file

Create view  email_form.php and make the form to entering email and one button to send mail

application/views/ email_form.php

<!DOCTYPE html> 
<html lang = "en"> 
        <meta charset = "utf-8"> 
        <title>CodeIgniter Email Example</title> 
        echo $this->session->flashdata('email_sent');
        echo form_open('/Email_controller/send_mail');

        <input type = "email" name = "email" required /> 
        <input type = "submit" value = "SEND MAIL"> 

        echo form_close();

Code is 100% tested it will work for you 


Make sure you have changed the default controller in application/config/routes.php 

$route['default_controller'] = 'Email_controller';