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’] = ‘smtp.company.com’;
$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(‘fromemail@company.net’, ‘Company Name/Admin’);

$this->email->to($empemail / ‘someone@example.com’);

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

$this->email->send();

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

Thats it..very simple..right 😉

Reference Link : Click , another

Advertisements

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.’);

to

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 🙂

Steps:

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

<?php

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

?>
<table class=”table table-bordered”>

<tbody>

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

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

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

</tr>
</tbody>
</table>
&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>

<?php

echo form_close();

?>

2. Add this code in Controller page..

public function changepwd(){
$this->load->library(‘form_validation’);
$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)
{
$this->load->view(‘settings’);

}
}
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;

}else
$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 🙂