Bagus Bala Bagus Bala - 1 year ago 80
PHP Question

Codeigniter Email Confirmations

I m new in Codeigniter. I want to create a login & registration page in my project. Login and register is success but if i want to confirm email it always say 404 not found if click the verify link. whats wrong with this code. Help me


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Voter_model extends CI_Model

function __construct()
// Call the Model constructor

//get the username & password from tbl_usrs
function get_user($username, $password)
$sql = "select * from user where username = '" . $username . "' and password = '" . $password . "' and status = '1'";
$query = $this->db->query($sql);
return $query->num_rows();

//insert into user table
function insertUser($data)
return $this->db->insert('user', $data);

//send verification email to user's email id
function sendEmail($to_email)
$from_email = ''; //change this to yours
$subject = 'Aktivasi Akun';
$message = 'Dear'. $username .'<br /><br />Please click on the below activation link to verify your email address.<br /><br />
'. site_url('voter/voter_register/verify') . md5($to_email) . '<br /><br /><br />Thanks<br />Admin, Gus bala';

//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://'; //smtp host name
$config['smtp_port'] = '465'; //smtp port number
$config['smtp_user'] = $from_email;
$config['smtp_pass'] = ''; //$from_email password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes

//send mail
$this->email->from($from_email, 'Admin Evoting');
return $this->email->send();

//activate user account
function verifyEmailID($key)
$data = array('status' => 1);

$this->db->where(md5('email'), $key);
$this->db->update('user', $data);


Answer Source

This is minor issue of your code

Assume your md5($to_email) is equal to 15253545. And in your mail sent this number via mail like this site_url('voter/voter_register/verify').md5($to_email)

So what you set is

there is no any function call like this verify15253545. Cz you are missing / on the URL. So fix is

                                     ^ Missing / on here

Now your URL reach the verify and passed data to $hash

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download