function gp_mail_config_ready(): array { $smtpConfig = __DIR__ . '/../smtp_config.php'; if (file_exists($smtpConfig)) { require_once $smtpConfig; } if (!defined('GP_MAIL_ENABLED') || GP_MAIL_ENABLED !== true) { return [false, 'SMTP is disabled. Open smtp_config.php, add your Hostinger/Gmail SMTP details, then set GP_MAIL_ENABLED to true.']; } $autoload = __DIR__ . '/../vendor/autoload.php'; if (!file_exists($autoload)) { return [false, 'PHPMailer is missing. Upload the vendor folder or run composer install.']; } require_once $autoload; return [true, 'SMTP ready.']; } function gp_mail_build(): array { [$ready, $message] = gp_mail_config_ready(); if (!$ready) { return [null, $message]; } $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = GP_MAIL_HOST; $mail->SMTPAuth = true; $mail->Username = GP_MAIL_USERNAME; $mail->Password = GP_MAIL_PASSWORD; $secure = defined('GP_MAIL_SECURE') ? GP_MAIL_SECURE : 'tls'; if ($secure === 'ssl') { $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; } else { $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; } $mail->Port = GP_MAIL_PORT; $mail->CharSet = 'UTF-8'; $mail->setFrom(GP_MAIL_FROM_EMAIL, GP_MAIL_FROM_NAME); return [$mail, 'Mailer ready.']; } function gp_mail_send_registration_otp(string $toEmail, string $toName, string $otp): array { [$mail, $message] = gp_mail_build(); if (!$mail) { return [false, $message]; } try { $safeName = htmlspecialchars($toName ?: 'Teacher', ENT_QUOTES, 'UTF-8'); $safeOtp = htmlspecialchars($otp, ENT_QUOTES, 'UTF-8'); $mail->addAddress($toEmail, $toName ?: $toEmail); $mail->isHTML(true); $mail->Subject = 'Your GradePilot PH OTP Code'; $mail->Body = "
Hello {$safeName}, use this OTP code to finish creating your GradePilot account:
This code expires in 10 minutes.
If you did not request this, you can ignore this email.
Enter your account email. GradePilot will send a secure reset link that expires in 1 hour.
Back to loginUsing XAMPP? If Gmail SMTP is disabled, a local test link appears for development only.