我尝试使用CodeIgniter框架通过电子邮件忘记密码,发送密码更改通知电子邮件已经正常工作。但是当我打开电子邮件并点击链接更改密码时,调用视图没有出现..我的脚本出了什么问题?
这是我的控制器
public function forgot()
{
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|callback_email_check');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('email/email_check');
}
else
{
$email= $this->input->post('email');
$this->load->helper('string', 6);
$rs= random_string('alnum', 12);
$data = array(
'rs' => $rs
);
$this->db->where('email', $email);
$this->db->update('user', $data);
//now we will send an email
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@xxx.esy.es ',
'smtp_pass' => 'xxxxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
//$data = array('tes' => 'tester');
//$message = $this->load->view('v_email',$data,TRUE);
$this->email->set_newline("\r\n");
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$this->email->from('xx@xx.esy.es', 'xxx');
$this->email->to($email);
$this->email->subject('Get your forgotten Password');
$this->email->message($this->load->view('email/email_forgot', $data, TRUE));
if($this->email->send())
{
$data = array ( 'isi' => 'login/vforgot');
$this->load->view('layout/wrapper',$data);
}else
{
$data = array ( 'isi' => 'login/vgagal');
$this->load->view('layout/wrapper',$data);
}
}
}
查看已发送的电子邮件
<tr>
<td style="color:#ffffff;font-family:Helvetica,Arial,sans-serif;font-size:15px;font-weight:bold;line-height:100%;padding-top:18px;padding-right:15px;padding-bottom:15px;padding-left:15px" align="center" valign="middle">
<a href="<?php echo site_url('/login/register/get_password/index/'.$rs); ?>"style="color:#ffffff;text-decoration:none" target="_blank">Reset Password</a>
</td>
</tr>
控制器get_password
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Get_password extends CI_Controller
{
public function index($rs=FALSE)
{
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[7]|max_length[20]|matches[passconf]|md5');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
echo form_open();
$this->load->view('email/gp_form');
}
else
{
$query=$this->db->get_where('user', array('rs' => $rs), 1);
if ($query->num_rows() == 0)
{
show_error('Sorry!!! Invalid Request!');
}
else
{
$data = array(
'password' => $this->input->post('password'),
'rs' => ''
);
$where=$this->db->where('rs', $rs);
$where->update('user',$data);
echo "Congratulations!";
}
}
}
}
观看gp_form
<?php echo validation_errors();
echo "Password :".form_password('password', '');
echo "Password Confirmation :".form_password('passconf', '');
echo form_submit('submit', 'Submit');
?>
此结果klik表单电子邮件
http://xxxxxx.com/login/register/get_password/index/cfCZm29TPrT6
未找到404页面
找不到您请求的页面。
答案 0 :(得分:1)
您传递的完整网址是什么?如果你得到了404,那是因为你的页面丢失了。
您是否在.htaccess中设置了友好的网址?如果没有,那么URL将是
http://example.com/index.php/login/register/get_password/index/cfCZm29TPrT6
答案 1 :(得分:0)
您可能错过了application/config/routes.php
文件中的路线。此URL的必要路由类似于(取决于文件结构):
$route['login/register/get_password/index/(:any)'] = 'get_password/index/$1';
在CodeIgniter中使用路由功能非常强大,因为您可以使用以下路由语法将这个相当长的URL更改为更短的URL,例如http://example.com/login/get_password/cfCZm29TPrT6:
$route['login/get_password/(:any)'] = 'get_password/index/$1';
您可以在http://www.codeigniter.com/user_guide/general/routing.html
的CodeIgniter手册中详细了解路由答案 2 :(得分:0)
尝试使用它,如果它可以工作:
<a href="<?php echo site_url('get_password/index/'.$rs); ?>"style="color:#ffffff;text-decoration:none" target="_blank">Reset Password</a>