我正在尝试忘记密码。因此,如果用户忘记了密码,他可以通过转到忘记密码页面来找回密码。尽管一切似乎都很完美,但我确实收到了成功消息"请检查您的电子邮件地址",并且验证也很完美。数据库表还在 md5 中重新生成了一个密码,并且还生成了一个 rs = 随机字符串。但是我没有收到电子邮件,我已经尝试了不同的电子邮件hotmail,gmail接收。对于发送,我只使用了gmail,但我确实尝试了2个不同的gmail帐户。我还遇到了一个奇怪的问题,那就是,如果我使用 account1@gmail.com 页面会永远加载,但是当我使用 account2@gmail.com 页面成功加载并显示成功消息时。还有一件事..当新用户注册时发送电子邮件,两者的代码相同(复制粘贴到不同的功能中),但是当我忘记密码时它不起作用。下面是我的控制器和视图文件。
控制器:我的网站
public function change_password()
{
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_email_check');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('mysite/email_check');
}
else
{
$email= $this->input->post('email');
$this->load->helper('string');
$rs= random_string('alnum', 12);
$data = array(
'rs' => $rs
);
$this->db->where('email', $email);
$this->db->update('user', $data);
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'account1@gmail.com';
$config['smtp_pass'] = 'mypassword';
$this->load->library('email', $config);
$this->email->from('account1@gmail.com', 'Admin');
$this->email->to($this->input->post('email'));
$this->email->subject('Get your forgotten Password');
$this->email->message('Please go to this link to get your password.
http://localhost/final-project/get_password/index/'.$rs );
$this->email->send();
echo "Please check your email address.";
}
}
get_password控制器用于重置它。
查看文件 : email_check
<?php echo validation_errors(); ?>
<form action="<?php site_url('mysite/change_password'); ?>" method="post">
<h2> email</h2>
<input type="text" size="30" id="email" name="email"/>
<br/>
<input type="submit"name="submit" value="Submit"/>
</form>
我终于发现了问题所在。代码非常好,但我仍然无法弄清楚为什么它不起作用。
我只需要添加这一行:
$this->email->set_newline("'r'n");
后:
$this->load->library('email', $config);
现在电子邮件已发送。我希望这也可以帮助许多提出类似问题的人。