PHP MVC CodeIgniter Laravel Core PHP MORE

Forgot password in MVC with example


Here is the Controller file hello.php which inside controllers folder

controllers/hello.php

<?php


class Hello extends Controller {

	function __construct() {
		parent::__construct();
	}
function forgot_password(){ if(isset($_POST['forgot'])) { $email=$this->input->post('email'); $que=$this->db->query("select email,pass from user_data where email='$email'"); $row=$que->row(); $user_email=$row->email; if((!strcmp($email, $user_email))){ $pass=$row->pass; /*Mail Code*/ $to = $user_email; $subject = "Password"; $txt = "Your password is $pass ."; $headers = "From: password@example.com" . "\r\n" . "CC: ifany@example.com"; mail($to,$subject,$txt,$headers); } } $this->view->render('hello/forgot_pass'); } } ?>

Here is the view file forgot_passl.php which inside views folder contains the form.

views/hello/forgot_pass.php

<!DOCTYPE html>
<html>
<body>
<form method="post" action="forgot_password"> 
	Email:<br>
	<input type="email" name="email"><br> 
	
	
	<input type="submit" name="forgot">
</form>
</html>
</body>
Path to run : localhost/project_folder_name/view_folder_name/view_filename
Example: localhost/mvc/hello/send_mail