Codeigniter Ion_auth在用户激活时发送第二封电子邮件

时间:2014-03-16 11:50:44

标签: php codeigniter email ion-auth

我在我的Codeigniter项目中使用Ion_Auth,我想在用户激活帐户后发送第二封电子邮件,我正在查看代码,实际上我正在尝试的是:

在我的控制器中

$activation = $this->ion_auth->activate($id, $code, $reciver);

Ion_auth_model->activate()

我想向已激活的用户发送另一封电子邮件,但我真的不知道应该怎么做

我做了什么,似乎工作但如果有更好的方法,不使用如上所述的这么多代码,欢迎

//activate the user
public function activate($id, $code = false) {
    if ($code !== false) {

        $btc_reciver = $this->bitcoin->getnewaddress();
        $this->load->model('ion_auth_model');
        $this->load->library('email');
        $user = $this->ion_auth_model->user($id)->row();
        $identity = $this->config->item('identity', 'ion_auth');
        $activation = $this->ion_auth->activate($id, $code, $btc_reciver);
        $data = array(
            'btc_send_address' => $btc_reciver,
            'identity' => $user->{$identity},
            'username' => $user->username,
            'id' => $user->id,
            'email' => $user->email,
        );
        $message = $this->load->view($this->config->item('email_templates', 'ion_auth') . $this->config->item('email_account_confirmation', 'ion_auth'), $data, true);
        $this->email->clear();
        $this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
        $this->email->to($user->email);
        $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_activation_subject'));
        $this->email->message($message);


        if ($this->email->send() == TRUE) {
            $this->session->set_flashdata('message', $this->ion_auth->messages());
            redirect("login", 'refresh');
        }

    } else if ($this->ion_auth->is_admin()) {
        $activation = $this->ion_auth->activate($id);
    }

    if ($activation) {
        //redirect them to the auth page
        $this->session->set_flashdata('message', $this->ion_auth->messages());
        redirect("login", 'refresh');
    } else {
        //redirect them to the forgot password page
        $this->session->set_flashdata('message', $this->ion_auth->errors());
        redirect("forgot_password", 'refresh');
    }
}

1 个答案:

答案 0 :(得分:0)

您只需在“post_activate_successful”触发器中添加一个挂钩即可发送电子邮件。这是一篇解释如何使用钩子的文章:

http://www.codebyjeff.com/blog/2013/01/using-hooks-with-ion_auth