Reputation:
Hi everyone i am trying to send an email verification sms to a registered user. the message is getting sent and the confirmation work but the 'status' row in the data base doesn't update to 1 after authentication clicked.
here is my code CONTROLLER
public function verify($email_code, $email_address) {
if($this->user_model->verifyEmail($email_code, $email_address)){
$this->load->view('templates/header');
$this->load->view('users/email_validated');
$this->load->view('templates/footer');
} else {
echo 'error'.$this->config->item('admin_email');
}
}
here is my code MODEL
public function send_validation_email() {
$username = $this->input->post('username');
$email = $this->input->post('email');
$sql = "SELECT id, register_date FROM users WHERE email = '" .$email ."' LIMIT 1";
$result = $this->db->query($sql);
$row = $result->row();
$this->email_code = md5((string)$row->register_date);
$email_code = $this->email_code;
$this->email->set_mailtype('html');
$this->email->from($this->config->item('bot_email'),'talkativs');
$this->email->to('[email protected]');
$this->email->subject('activatorrrrr');
$message .= '<p> Dear ' . $username.',</p>';
$message .= '<p> confim mail sharpaly <a href="' . base_url().'users/verify/'.$email.'/'.$email_code.'">click here</a></p>';
$message .= '<p> Thanks</p>';
$this->email->message($message);
$this->email->send();
if ($this->email->send()){
return "sent";
} else {
return "failed to send";
}
}
function verifyEmail($email_code, $email_address) {
$data = array('status' => 1);
$this->db->where('email', $email_address);
$this->db->where('md5(register_date)', $email_code);
return $this->db->update('users', $data);
}
Upvotes: 1
Views: 12859
Reputation: 7302
Your method has wrong mapping for parameters..
public function verify($email_code, $email_address) {
if($this->user_model->verifyEmail($email_code, $email_address)){
$this->load->view('templates/header');
$this->load->view('users/email_validated');
$this->load->view('templates/footer');
} else {
echo 'error'.$this->config->item('admin_email');
}
}
It must be like :
public function verify($email_address, $email_code) {
if($this->user_model->verifyEmail($email_code, $email_address)){
$this->load->view('templates/header');
$this->load->view('users/email_validated');
$this->load->view('templates/footer');
} else {
echo 'error'.$this->config->item('admin_email');
}
}
You sending the email like below example:
'<p> confirm mail sharply <a href="' . base_url().'users/verify/'.$email.'/'.$email_code.'">click here</a></p>';
Which produce the following output in email:
<p>confirm mail sharply <a href="http:// www.site.com/users/verify/[email protected]/AC67">click here</a></p>
Notice the format of link:
users{Controller}/verify{Method}/[email protected]{First Param}/AC67{Second Param}
So your method must be use method ($email, $code)... simple.. :)
Because CodeIgniter takes url parameters in same order as they supplied..
Upvotes: 1