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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘