dongsi3826 2015-07-09 07:50
浏览 62

链接通过邮件php codeigniter

For user identification,I need to send the url of localhost via mail in php codeigniter . . I also need to pass the token which I had generated for that user along with the url. My user need to be verified by clicking that link which must be identified by the corresponding token. And I have no idea about passing variables via url . . How could I proceed my code?

My code follows. .

<?php
class Site_model extends CI_Model
{
    public function __construct()
    {
        parent:: __construct();
        $this->load->database();

    }
    public function insert($token)
    { 
        $data = array(
        'name'=>$this->input->post('name'),
        'email'=>$this->input->post('email'),
        'phone'=>$this->input->post('phone'),
        'date_of_birth'=>$this->input->post('dob'),
        'user_type'=>$this->input->post('utype'),
        'token'=>$token,
        );

        $this->db->insert('tbl_user',$data);

        $email=$this->input->post('email');

        $config = array(
       'protocol'  => 'smtp',
       'smtp_host' => 'ssl://smtp.googlemail.com',
       'smtp_port' => '465',
       'smtp_user' => 'someone@gmail.com',
       'smtp_pass' => 'something',
       'mailtype'  => 'html',
       'starttls'  => true,
       'newline'   => "
"
       );
        $this->load->library('email',$config);
        $this->email->From("someone@gmail.com");
        $this->email->to($email);
        $this->email->subject('test');
        $this->email->message("worked");
        $this->email->send();

        if($this->email->send()) {
            echo '<script>alert("Email sent successfully")</script>';
            } else {
        $this->email->print_debugger();
}




    }



}


?>
  • 写回答

1条回答

  • doutun9179 2015-07-09 08:12
    关注

    To pass data along with a URL you can use URI segments.

    In your situation the easiest thing to do would probably to be to use GET parameters. To use these you would output the link as normal and then append a parameter to the end like:

    http://yoursite.com/user/verify/**token**

    This example would be for if you had a user controller with a function called verify. The method signature would be something like:

    public function verify($token = NULL) { ... }
    

    The last part of the URL will populate $token which you can then use in the verify function to check the user is valid and perform any actions you need to.

    You could always re-route a URL to an alternative method through routes.php if you needed to as well.

    Simply pass this link with the token inserted into the email so that when the user clicks on it then the verify method runs with the necessary parameters.

    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题