使用电子邮件验证激活帐户

时间:2017-02-05 13:27:53

标签: php codeigniter

  

发生错误。请在错误####@admin.com上联系管理员   通过电子邮件激活确认您的帐户,请联系#### @ admin.com

尝试通过电子邮件地址设置帐户验证,电子邮件会成功发送到用户地址,但当用户点击发送到其帐户的链接时,会出现以上错误。

来自电子邮件的链接

href="' . base_url() . 'register/validate_email/' . $email . '/' . $email_code . '"

当您点击电子邮件中的链接时,它会指向

注册控制器

public function validate_email($email_address, $email_code)
{
    $email_code=trim($email_code);
    $validated =  $this->model_user->validate_email($email_address,           $email_code);
    if($validated ==  true)
    {
        $this->load->view('includes/header');
        $this->load->view('registration/view_email_validated', array('s_email' => $email_address));
        $this->load->view('includes/footer');
    }
    else{
        echo 'Error confirming your account via email ativation, Please       contact '. $this->config->item('admin_email');
    }
}

Model_user

public function validate_email($email_address, $email_code)
{
     $sql = "select student_id, s_email, s_name from qcs_student where s_email = '{ $email_address }' limit 1";
    $result = $this->db->query($sql);
    $row = $result->row();
    if($result->num_rows() == 1 && $row->s_name)
    {
        if(md5((string)$row->student_id) == $email_code)
        {
            $result = $this->activate_account($email_address);
        }
        else
        {
            $result = false;
        }
        if($result = true)
        {
            return true;
        }
        else
        {
            echo 'Something is wrong, Please contact Administrator at '. $this->config->item('admin_email');
            return false;
        }
    }
    else
    {
        echo 'There was an error. Please contact Admin at '. $this->config->item('admin_email');
    }
}

1 个答案:

答案 0 :(得分:0)

更新$ sql如下:(删除{} guard for email_address):

$sql = "select student_id, s_email, s_name from qcs_student where s_email = '$email_address' limit 1";