Guest User

Untitled

a guest
Aug 17th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <form action="<?php echo base_url() . "welcome/forgotpassword" ?>" method="POST">
  2.  
  3. <div class="form-group has-feedback">
  4. <input type="email" class="form-control" placeholder="Email" name="user_email" />
  5. <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
  6. </div>
  7. <div class="row">
  8. <div class="col-xs-4">
  9. <input type="submit" class="btn btn-primary btn-block btn-flat" value="Send">
  10.  
  11. </div>
  12. </div>
  13. </form>
  14.  
  15. public function forgotpassword(){
  16.  
  17. $email = $this->input->post('user_email');
  18. $findemail = $this->main_model->ForgotPassword($email);
  19. $this->load->view('forgotpassword');
  20. if ($findemail) {
  21. $this->main_model->sendpassword($findemail);
  22. } else {
  23.  
  24. $this->session->set_flashdata('msg', 'Email not found!');
  25.  
  26. }
  27. }
  28.  
  29. public function sendpassword($data) {
  30. $email = $data['user_email'];
  31. print_r($data);
  32. $query1 = $this->db->query("SELECT * from user_registration where user_email = '" . $email . "'");
  33. $row = $query1->result_array();
  34. print_r($email);
  35.  
  36. if ($query1->num_rows() > 0) {
  37.  
  38. $passwordplain = "";
  39. $passwordplain = rand(999999999, 9999999999);
  40. $newpass['user_password'] = md5($passwordplain);
  41. $this->db->where('user_email', $email);
  42. $this->db->update('user_registration', $newpass);
  43. $mail_message = 'Dear ' . $row[0]['full_name'] . ',' . "rn";
  44. $mail_message .= 'Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>' . $passwordplain . '</b>' . "rn";
  45. $mail_message .= '<br>Please Update your password.';
  46. $mail_message .= '<br>Thanks & Regards';
  47. $mail_message .= '<br>Your company name';
  48. require FCPATH . 'assets/PHPMailer/PHPMailerAutoload.php';
  49. $mail = new PHPMailer;
  50. $mail->isSMTP();
  51. $mail->SMTPSecure = "tls";
  52. $mail->Debugoutput = 'html';
  53. $mail->Host = "ssl://smtp.googlemail.com";
  54. $mail->Port = 465;
  55. $mail->SMTPAuth = true;
  56. $mail->Username = "xxxxxxxxx@gmail.com";
  57. $mail->Password = "xxxxxxxx";
  58. $mail->setFrom('xxxxxxx@gmail.com', 'admin');
  59. $mail->IsHTML(true);
  60. $mail->addAddress('user_email', $email);
  61. $mail->Subject = 'OTP from company';
  62. $mail->Body = $mail_message;
  63. $mail->AltBody = $mail_message;
  64.  
  65. if ($mail->send()) {
  66.  
  67. echo '<script>alert("Message Send")</script>';
  68. $this->session->set_flashdata('msg', 'Failed to send password, please try again!');
  69. } else {
  70. echo '<script>alert("Sending Failed")</script>';
  71. echo $this->email->print_debugger();
  72. $this->session->set_flashdata('msg', 'Password sent to your email!');
  73. }
  74.  
  75. }
  76. }
Add Comment
Please, Sign In to add comment