prepare("SELECT * FROM brand_details"); $stmt_brand->execute(); $result_brand = $stmt_brand->get_result(); if ($result_brand->num_rows > 0) { $brand = $result_brand->fetch_assoc(); $domainName = $brand['domain_name']; $webUrl = $brand['web_url']; $aboutDesc = $brand['about_desc']; $lightLogo = $brand['light_logo']; $darkLogo = $brand['dark_logo']; $ogImage = $brand['og_image']; $favicon = $brand['favicon']; $themeColor = $brand['theme_color']; $secondaryColor = $brand['secondary_color']; } $stmt_brand->close(); //For sending email use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require '../PHPMailer/src/Exception.php'; require '../PHPMailer/src/PHPMailer.php'; require '../PHPMailer/src/SMTP.php'; if (!isset($_SESSION["email"])) { header("Location: signin"); exit; } // Verify admin access $stmt_admin = $connect->prepare("SELECT role FROM admindb WHERE email = ?"); $stmt_admin->bind_param("s", $_SESSION['email']); $stmt_admin->execute(); $result_admin = $stmt_admin->get_result(); $admin = $result_admin->fetch_assoc(); $stmt_admin->close(); if (!$admin || $admin["role"] !== 'admin') { $msg['errorMsg'] = "Unauthorized access!"; header('Content-Type: application/json'); echo json_encode($msg); exit; } $msg = []; if (isset($_POST['userId']) && isset($_POST['value'])) { $userId = $_POST['userId']; $value = $_POST['value']; // Validate status value if ($value !== '0' && $value !== '1') { $msg['errorMsg'] = "Invalid status value!"; header('Content-Type: application/json'); echo json_encode($msg); exit; } $updateToken = bin2hex(random_bytes(10)); // Update status in users table $stmt = $connect->prepare("UPDATE users SET status = ?, token = ? WHERE id = ?"); $stmt->bind_param("ssi", $value, $updateToken, $userId); if ($stmt->execute()) { $msg['successMsg'] = $value == '1' ? "User verified successfully!" : "User access suspended!"; $msg['value'] = $value; $msg['userId'] = $userId; // Query to check if the email exists in the database $stmt_user = $connect->prepare("SELECT user_name, email FROM users WHERE id = ?"); $stmt_user->bind_param("i", $userId); $stmt_user->execute(); $result = $stmt_user->get_result(); $user = $result->fetch_assoc(); $stmt_user->close(); $username = $user['user_name']; $email = $user['email']; $capitalizedString = ucwords($username); // Create a new PHPMailer instance $mail = new PHPMailer(true); try { // Server settings $mail->isSMTP(); $mail->Host = $emailServer; $mail->SMTPAuth = true; $mail->Username = $emailUserName; $mail->Password = $emailPassword; $mail->SMTPSecure = $encryptionType; $mail->Port = $smtpPort; // Recipients $mail->setFrom($senderEmail, $senderName); $mail->addAddress($email, $username); // Content $mail->isHTML(true); // Your HTML email template content $message = ' '; if($value == "1") { $message .= 'Account Verification Update'; } if($value == "0") { $message .= 'Urgent: Account Suspension - Action Required'; } $message .= '
'; if($value == "1") { $message .= ' '; } $message .= '

Hello '.$capitalizedString.',

'; if($value == "1") { $message .= '

We are pleased to inform you that, upon request, our admin has manually verified your account.

If you have any further inquiries or require assistance, feel free to reach out to our support team.

'; } if($value == "0") { $message .= '

We regret to inform you that your account has been temporarily suspended.

This action may be due to a violation of our terms of service or security concerns.

Please contact our support team for further assistance in resolving this matter.

If no action is taken, your account will be deleted soon without further notice.

'; } $message .= '
Continue to Login
'; if($value == "1") { $message .= '

Thank you for choosing '.$domainName.'.

'; } if($value == "0") { $message .= '

Thank you for your understanding.

'; } $message .= '

Best regards,
'.$senderName.' Team

The email is auto generated. Please, don't reply.
© '.date('Y').' '.$domainName.'
'; if($value == "1") { $mail->Subject = 'Account Verification Update - '.$domainName; } if($value == "0") { $mail->Subject = 'Urgent: Account Suspension - Action Required - '.$domainName; } $mail->Body = $message; // Send the email $mail->send(); } catch (Exception $e) { $msg['errorMsg'] = "Error: ". $mail->ErrorInfo; } } else { $msg['errorMsg'] = "Failed to update status!"; } $stmt->close(); } else { $msg['errorMsg'] = "Invalid request!"; } // Escape HTML and whitespace for each value in $msg foreach ($msg as &$value) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); } header('Content-Type: application/json'); echo json_encode($msg, JSON_UNESCAPED_UNICODE); exit; ?>