send email after registration
<p>my controller code is</p>

<pre><code>public function register()
{
    $this-&gt;form_validation-&gt;set_rules('employer_name', 'Employer Name', 'trim|required|min_length[3]|max_length[30]');
    $this-&gt;form_validation-&gt;set_rules('username', 'Usename Name', 'trim|required|min_length[3]|max_length[30]');
    $this-&gt;form_validation-&gt;set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[employer_registration.email]');
    $this-&gt;form_validation-&gt;set_rules('mobile', 'Mobile', 'trim|required|numeric');
    $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|matches[cpassword]|md5');
    $this-&gt;form_validation-&gt;set_rules('cpassword', 'Confirm Password', 'trim|required');

    if ($this-&gt;form_validation-&gt;run() == FALSE)
    {
        $this-&gt;load-&gt;view('employer/emp_register');
    }
    else
    {
     //insert the user registration details into database

 $data = array(
                'employer_name' =&gt; $this-&gt;input-&gt;post('employer_name'),
                'username' =&gt; $this-&gt;input-&gt;post('username'),
                'email' =&gt; $this-&gt;input-&gt;post('email'),
                'mobile' =&gt; $this-&gt;input-&gt;post('mobile'),
                'password' =&gt; $this-&gt;input-&gt;post('password')
            );
             $email = $this-&gt;input-&gt;post('email');
            $username = $this-&gt;input-&gt;post('username');
    if ($this-&gt;Employer_model-&gt;insertUser($data)){
                $this-&gt;load-&gt;library('email');
                $config_email['protocol'] = 'mail';
                $config_email['mailtype'] = 'html';
                $this-&gt;email-&gt;initialize($config_email);

                $this-&gt;email-&gt;from('test@domainname.com', 'domainname.com');
                $this-&gt;email-&gt;to($email);
                $this-&gt;email-&gt;subject('We welcome you');
                $this-&gt;email-&gt;message("Thanks for registration your username:$usernsme ");

                if ($this-&gt;email-&gt;send())
                {
                    echo "&lt;script&gt;alert('Email sent to $email mail id')&lt;/script&gt;";
                } else {
                    $data['reg_status'] = "SOrry registration fail";
                }

                redirect('Employer/index');
}
else
        {
           echo "&lt;script&gt;alert('Oops! Error.  Please try again later!!!')&lt;/script&gt;";
        }
    }

}
</code></pre>

<p>In my controller i validate all user details after that data inserting into data base , collect email and username into variable for sending mail purpose
I want to send email to user after successful registration, mail send to their registered email id.</p>

<pre><code>function insertUser($data)
{
    return $this-&gt;db-&gt;insert('employer_registration', $data);
}
</code></pre>

<p>this is my simple model function</p>