require_once 'db.php'; require 'vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; //ob_start(); function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } include_once 'header.php'; echo "
"; if(isset($_POST['reset-pw'])){ $email = $_POST['email']; $pw = generateRandomString(); $r = $conn->query("UPDATE users SET password = '$pw' WHERE email = '$email'"); if(!$r) $status = [ 'msg' => 'Unexpected error occured', 'class' => 'alert-danger' ]; else{ $mail = new PHPMailer(true); //Server settings //$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.hostinger.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'info@banzararestaurant.in'; // SMTP username $mail->Password = 'Info@123'; // SMTP password $mail->SMTPSecure = 'SSL'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted //$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('info@banzararestaurant.in', 'Hostinger'); $mail->addAddress($email); // Add a recipient // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Reset password - Banzararestaurant'; $mail->Body = 'Your new password is '. $pw; if($mail->send()) $status = [ 'msg' => 'New password sent to your email', 'class' => 'alert-success' ]; else $status = [ 'msg' => 'Unexpected error occured', 'class' => 'alert-danger' ]; } } ?>