I have a user login/registration system on my simple site everything works great but I would like to have a function that sends a generic email to the user when the logout button is clicked. probably saying something like please send us an email regarding your findings on our site.
the site is an entertainment agency that books out Carnival equipment, registration and login is purely for users to view prices should they be interested in the actual product.
i have no idea where or how to implement anything like this.
my understanding is i must create a query to the databases requesting email from email column and if user email address exist proceed with the email sending (if they are at the point of logout then that means email address is available in database) then once it is sent log user out and redirect to a page. i just dont know how to do the query exactly.
any advice would be much appreciated
ps, I don't know what documentation you would need to see in order to see what i have done?
this is my logout page:
<?php
require_once 'db.php';
session_start();
if (isset($_SESSION['username']) && !empty($_SESSION['username'])):
if (isset($_GET['action']) && !empty($_GET['action'])) {
$action = $_GET['action'];
if ($action == "logout") {
$stmt = $pdo->prepare("SELECT email FROM users WHERE email = ? ");
$stmt->execute([$_SESSION['username']]);
$email = $stmt->fetchColumn();
$message = "Hellow you just used our website....";
if (mail($email, "Feedback", $message)) {
// the email is sent now log the user out.
session_destroy();
header("location:login_page.php");
exit();
}
}
}
endif;
?>