Email Configuration in CodeIgniter

hey guys,

lets see how to configure email in codeigniter today..

1. Create a page name email.php in project/application/config/

copy this code over there..

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
$config[‘protocol’] = ‘smtp’;
$config[‘smtp_host’] = ‘’;
$config[‘smtp_port’] = 25;


2. Goto your controller page..just paste this below code where ever it requires to send a mail..

$this->load->library(’email’, $config);
$this->email->from(‘’, ‘Company Name/Admin’);

$this->email->to($empemail / ‘’);

$this->email->subject(‘Related Subject’);
$this->email->message(‘Your message ..’);


echo $this->email->print_debugger();

Thats it..very simple..right 😉

Reference Link : Click , another


Code Igniter Error: Disallowed Key Characters

1. Search for function _clean_input_keys on /system/core/Input.php

2. Modify this line

exit(‘Disallowed Key Characters.’);


exit(‘Disallowed Key Characters.’ .  $str);

3. Refresh page to see the characters which generate the error

4. If you need to add those characters into the exception list, just add to this line

if ( ! preg_match(“/^[a-z0-9:_\/-]+$|/i”, $str))

I add | (pipe) character on the example above

Note: In most cases you can resolve the problem just by clearing the cookies

Create Change Password functionality in codeigniter along with css framework

hey guys, lets see the change password functionality in codeigniter using css framework called twitter bootstrap 🙂


1. Create a view in codeigniter for a form displaying old password,new & confirm password labels…


echo form_open(‘main/changepwd’);
echo validation_errors();

<table class=”table table-bordered”>


<td><small><?php echo “Old Password:”;?></small></td>
<td><?php echo form_password(‘opassword’);?></td>

<td><small><?php echo “New Password:”;?></small></td>
<td><?php echo form_password(‘npassword’);?></td>

<td><small><?php echo “Confirm Password:”;?></small></td>
<td><?php echo form_password(‘cpassword’);?></td>

&nbsp;&nbsp;<div id=”some”style=”position:relative;”><button type=”submit” class=”btn btn-primary”><i class=” icon-ok-sign icon-white”></i>&nbsp;Submit</button>


echo form_close();


2. Add this code in Controller page..

public function changepwd(){
$this->form_validation->set_rules(‘opassword’,’Old Password’,’required|trim|xss_clean|callback_change’);
$this->form_validation->set_rules(‘npassword’,’New Password’,’required|trim’);
$this->form_validation->set_rules(‘cpassword’,’Confirm Password’,’required|trim|matches[npassword]’);

if($this->form_validation->run()!= true)

public function change() // we will load models here to check with database
$sql = $this->db->select(“*”)->from(“users”)->where(“email”,$this->session->userdata(’email’))->get();

foreach ($sql->result() as $my_info) {

$db_password = $my_info->password;
$db_id = $my_info->id;


if(md5($this->input->post(“opassword”)) == $db_password){

$fixed_pw = mysql_real_escape_string(md5($this->input->post(“npassword”)));
$update = $this->db->query(“Update `users` SET `password`=’$fixed_pw’ WHERE `id`=’$db_id'”)or die(mysql_error());
$this->form_validation->set_message(‘change’,'<div class=”alert alert-success”><a href=”#” class=”close” data-dismiss=”alert”>&times;</a>
<strong>Password Updated!</strong></div>’);
return false;

$this->form_validation->set_message(‘change’,'<div class=”alert alert-error”><a href=”#” class=”close” data-dismiss=”alert”>&times;</a>
<strong>Wrong Old Password!</strong> </div>’);

return false;


In 2 steps you easily did change password functionality in code igniter na.. 😉 good luck 🙂