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.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型