When a user fill in their email address in an form, I will check if the email address exist in the database.
Why are not the code working?
Here is my code:
php
<?php
session_start();
require 'database.php';
if(!empty($_POST['email'])):
$records = $conn->prepare('SELECT id,email,password FROM users WHERE email = :email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
echo 'Working';
if(isset($_REQUEST['email'])){
$email_to = $_REQUEST['email'];
$email_subject = "Forgotten password";
$email_from = "password@scoreplay.net";
$email_message = $results['password'];
$headers = 'From: ' .$email_from . "\r\n";
@mail($email_to, $email_subject, $email_message, $headers);
#header("Location: /success.php");
exit();
}
endif;
?>