链接通过邮件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();
}




    }



}


?>
doxrxwn2252
doxrxwn2252 你的带有令牌的URL是什么?
大约 5 年之前 回复
dsxmwin86342
dsxmwin86342 使用$data数组填充视图。$html=$this->load->view('path/to/view',$data,true);第3个参数告诉它返回内容而不是将其发送到输出缓冲区。然后只需使用$html填充消息($this->email->message($html))。
大约 5 年之前 回复

1个回答



要传递数据和URL,您可以使用URI段。</ p>

在您的情况下 最简单的事情可能是使用 GET </ code>参数。 要使用它们,您可以正常输出链接,然后将参数附加到末尾,如:</ p>

http://yoursite.com/user/verify/**token* * </ code> </ p>

如果您的 user </ code>控制器具有名为 verify </ code>的函数,则此示例适用于此示例。 方法签名类似于:</ p>

  public function verify($ token = NULL){...} 
</ code> </ pre>

URL的最后一部分将填充 $ token </ code>,然后您可以在 verify </ code>函数中使用它来检查用户是否有效并执行您需要执行的任何操作。 </ p>

如果需要,您也可以通过 routes.php </ code>将URL重新路由到替代方法。</ p>

< p>只需将此链接与插入到电子邮件中的令牌一起传递,这样当用户点击它时, verify </ code>方法就会运行必要的参数。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问