<form id="resetPassword" name="resetPassword" method="post" action="<?php echo base_url();?>My_Controller/ForgotPassword" onsubmit ='return validate()'>
<table class="table table-bordered table-hover table-striped">
<tbody>
<tr>
<td>Enter Email: </td>
<td>
<input type="email" name="email" id="email" style="width:250px" required>
</td>
<td><input type = "submit" value="submit" class="button"></td>
</tr>
</tbody> </table></form>
HTML視圖
public function ForgotPassword()
{
$email = $this->input->post('email');
$findemail = $this->MY_model->ForgotPassword($email);
if ($findemail) {
$this->MY_model->sendpassword($findemail);
} else {
echo "<script>alert(' $email not found, please enter correct email id')</script>";
redirect(base_url() . 'MY_controller/index', 'refresh');
}
}
該控制器功能
public function ForgotPassword($email)
{
$this->db->select('email');
$this->db->from('table');
$this->db->where('email', $email);
$query=$this->db->get();
return $query->row_array();
}
這從數據庫表中選擇電子郵件的借鑑作用
public function sendpassword($data)
{
$email = $data['email'];
$query1=$this->db->query("SELECT * from tablename where email = '".$email."' ");
$row=$query1->result_array();
if ($query1->num_rows()>0)
{
$passwordplain = "";
$passwordplain = rand(999999999,9999999999);
$newpass['password'] = md5($passwordplain);
$this->db->where('email', $email);
$this->db->update('employer_registration', $newpass);
$mail_message='Dear '.$row[0]['name'].','. "\r\n";
$mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
$mail_message.='<br>Please Update your password.';
$mail_message.='<br>Thanks & Regards';
$mail_message.='<br>Your company name';
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSendmail();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "hostname";
$subject = 'Testing Email';
$mail->AddAddress($email);
$mail->IsMail();
$mail->From = '[email protected]***.com';
$mail->FromName = 'admin';
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_message;
$mail->Send();
if (!$mail->send()) {
echo "<script>alert('msg','Failed to send password, please try again!')</script>";
} else {
echo "<script>alert('msg','Password sent to your email!')</script>";
}
redirect(base_url().'Jobseeker/index','refresh');
}
else
{
echo "<script>alert('msg','Email not found try again!')</script>";
redirect(base_url().'Jobseeker/index','refresh');
}
}
這種模式功能創建randome密碼和註冊郵箱
所以發送電子郵件,哪裏是問題嗎?你的問題在哪裏?你找到解決方案? – kishor10d
我的問題是,我不能用我的舊密碼更新新生成的代碼。 – Tejaswee