From 7a40c6f603d8a72001dd40dafe251d6a35a5831c Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Fri, 31 Jul 2026 19:55:46 +0200 Subject: [PATCH] enabling email for registration. --- auth.php | 18 ++++++++++++++++++ register.php | 5 ++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/auth.php b/auth.php index 7526790..141e80c 100644 --- a/auth.php +++ b/auth.php @@ -388,6 +388,24 @@ function generateRegistrationCode() { return str_pad((string) random_int(0, 999999), 6, '0', STR_PAD_LEFT); } +function sendRegistrationVerificationEmail($email, $code) { + $email = trim((string) $email); + if ($email === '') { + return false; + } + + $subject = 'Your KaI registration verification code'; + $message = "Hello,\n\n" + . "You requested to create a KaI account.\n" + . "Your verification code is: {$code}\n\n" + . "Please enter this code on the registration page to complete your account setup."; + $headers = "From: " . MAIL_FROM_NAME . " <" . MAIL_FROM . ">\r\n" + . "Reply-To: " . MAIL_FROM . "\r\n" + . "X-Mailer: PHP/" . phpversion(); + + return mail($email, $subject, $message, $headers); +} + function savePendingRegistration($username, $email, $password, $code) { if (session_status() === PHP_SESSION_NONE) { session_start(); diff --git a/register.php b/register.php index 74c6fc2..50d20ee 100644 --- a/register.php +++ b/register.php @@ -52,11 +52,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $errors[] = 'That username or email is already in use.'; } else { $code = generateRegistrationCode(); - if (savePendingRegistration($username, $email, $password, $code)) { + if (savePendingRegistration($username, $email, $password, $code) && sendRegistrationVerificationEmail($email, $code)) { $message = 'A verification code has been sent to ' . htmlspecialchars($email) . '. Please enter it below.'; - $message .= ' (For demo purposes, the code is: ' . htmlspecialchars($code) . ')'; } else { - $errors[] = 'Unable to start registration.'; + $errors[] = 'Unable to start registration. Please check that your email address is valid and the mail server is configured.'; } } }