我是Codeigniter PHP的新手
public function ForgotPassword($email)
{
$this->db->select('email');
$this->db->from('member');
$this->db->where('email', $email);
$query=$this->db->get();
$out = $query->result_array();
if (count($out) > 0) {
$email = $out[0]['email'];
return array('status'=>1, 'email'=>$email);
} else {
return array('status'=>0, 'msg'=>'email not found');
}
}
这是我的模型函数。此行给我空结果$out = $query->result_array();
,我不知道为什么,它应该给我电子邮件地址,以便我可以继续发送电子邮件。我想使用忘记密码功能向用户发送密码。
public function ForgotPassword()
{
$email = $this->input->post('email');
$findemail = $this->MY_model->ForgotPassword($email);
if ($findemail['status'] == 1) {
$this->MY_model->sendpassword($findemail);
} else {
echo " $email not found, enter correct email id";
}
}
这是我的控制器功能。在这里,我得到了$findemail
的空白值。我不知道为什么。
public function sendpassword($data)
{
$email = $data['email'];
$query1=$this->db->query("SELECT * from member where email = '".$email."' ");
$row=$query1->result_array();
if ($query1->num_rows() > 0) {
$passwordplain = "";
$passwordplain = rand(10000000,99999999);
$newpass['password'] = md5($passwordplain);
$this->db->where('email', $email);
$this->db->update('member', $newpass);
$mail_message='Dear '.$row[0]['username'].','. "\r\n";
$mail_message.=' Your <b>Password</b> is
<b>'.$passwordplain.'</b>'."\r\n";
require 'C:\xampp\htdocs\phpmailer\class.phpmailer.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSendmail();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$subject = 'Testing Email';
$mail->AddAddress($email);
$mail->IsMail();
$mail->From = 'vishal@gmail.com';
$mail->FromName = 'admin';
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_message;
$mail->Send();
if (!$mail->send()) {
echo "Failed to send password";
} else {
echo "Password sent ! check your mail";
}
} else {
echo "Email not found!!!!";
}
}
还有高级功能,它不发送电子邮件。我正在使用phpmailer发送电子邮件。请帮忙。
答案 0 :(得分:0)
如果模型名称为“ MY_model”,则在控制器文件中写入构造函数,然后将模型加载到其中,如下所示。
$index
并按如下所示修改控制器的ForgotPassword函数。
function __construct() {
parent::__construct();
$this->load->model('my_model');
}
我希望这会有所帮助。
答案 1 :(得分:0)
我做了一个检查数据库中是否存在电子邮件的功能。它名为CheckUser()。 然后在ForgotPassword()中调用CheckUser()(必须以$ email作为参数)。
<?php
public function CheckUser($email)
{
$response = $bdd->prepare('SELECT email FROM member WHERE email = :email');
$response->execute([
"email" => $$email
]);
$data = $response->fetchAll();
return $data[0];
}
public function ForgotPassword($email)
{
// here you call our new function
**低于CHECKUSER功能的调用UDPATE **
$out = $this->CheckUser($email);
// sizeof will return the lenght of the returned data from our CheckUser() function
if (sizeof($out) > 0){
$email = $out[0]['email'];
return array('status'=>1, 'email'=>$email);
}
else {
return array('status'=>0, 'msg'=>'email not found');
}
}
让我知道它是否有效。