1. Registration – public/login-register.php After the user is inserted successfully: php // After INSERT into users, get $new_user_id, $name, $email require_once __DIR__ . '/../admin/includes/EmailService.php'; $emailService = new EmailService($pdo); $emailService->sendTemplateEmail('welcome', $email, [ 'user_name' => $name, 'site_url' => SITE_URL ]); 2. Paystack Callback – public/user/gateways/verify-paystack.php Inside the processPayment() function, after updating the subscription: php $user_stmt = $pdo->prepare("SELECT full_name, email FROM users WHERE id = ?"); $user_stmt->execute([$user_id]); $user = $user_stmt->fetch(PDO::FETCH_ASSOC); require_once __DIR__ . '/../../../admin/includes/EmailService.php'; $emailService = new EmailService($pdo); $emailService->sendTemplateEmail('vip_upgrade', $user['email'], [ 'user_name' => $user['full_name'], 'expiry_date' => date('F j, Y', strtotime($expiry_date)) ]); $emailService->sendTemplateEmail('payment_confirmation', $user['email'], [ 'user_name' => $user['full_name'], 'amount' => '$' . number_format($amount, 2), 'currency' => 'USD', 'plan_name' => $plan_name, 'transaction_id' => $reference ]); 3. Admin Manual Approval – admin/transaction-approval.php When an admin approves a transaction (after the user is upgraded to VIP): php $user_stmt = $pdo->prepare("SELECT full_name, email FROM users WHERE id = ?"); $user_stmt->execute([$user_id]); $user = $user_stmt->fetch(PDO::FETCH_ASSOC); require_once __DIR__ . '/includes/EmailService.php'; $emailService = new EmailService($pdo); $emailService->sendTemplateEmail('vip_upgrade', $user['email'], [ 'user_name' => $user['full_name'], 'expiry_date' => date('F j, Y', strtotime($expiry_date)) ]); $emailService->sendTemplateEmail('payment_confirmation', $user['email'], [ 'user_name' => $user['full_name'], 'amount' => '$' . number_format($amount, 2), 'currency' => 'USD', 'plan_name' => $plan_name, 'transaction_id' => $transaction_id ]); 4. Referral Reward – public/login-register.php (or your referral function) When a user reaches 10 referrals and earns VIP days: php $user_stmt = $pdo->prepare("SELECT full_name, email FROM users WHERE id = ?"); $user_stmt->execute([$referrer_id]); $referrer = $user_stmt->fetch(PDO::FETCH_ASSOC); require_once __DIR__ . '/../admin/includes/EmailService.php'; $emailService = new EmailService($pdo); $emailService->sendTemplateEmail('referral_reward', $referrer['email'], [ 'user_name' => $referrer['full_name'], 'referral_count' => $new_count, 'vip_days' => 7, 'expiry_date' => date('F j, Y', strtotime($new_expiry)), 'referral_code' => $referral_code ]); 5. Bet of the Day Alert (Cron) – admin/cron-bet-of-the-day.php Create this new file: php query("SELECT id, full_name, email FROM users WHERE status = 'ACTIVE'"); $users = $stmt->fetchAll(PDO::FETCH_ASSOC); $emailService = new EmailService($pdo); foreach ($users as $user) { $emailService->sendTemplateEmail('bet_of_the_day_alert', $user['email'], [ 'user_name' => $user['full_name'], 'bet_of_the_day_link' => SITE_URL . '/bet-of-the-day.php' ]); } echo "Sent to " . count($users) . " users.\n"; 6. Subscription Expiry Reminder – admin/cron-expiry-reminder.php Create this new file: php prepare(" SELECT id, full_name, email, vip_expires_at FROM users WHERE user_tier = 'VIP' AND vip_expires_at BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY) "); $stmt->execute(); $users = $stmt->fetchAll(PDO::FETCH_ASSOC); $emailService = new EmailService($pdo); foreach ($users as $user) { $emailService->sendTemplateEmail('subscription_expiry', $user['email'], [ 'user_name' => $user['full_name'], 'expiry_date' => date('F j, Y', strtotime($user['vip_expires_at'])), 'renewal_link'=> SITE_URL . '/user/billing.php' ]); } echo "Sent to " . count($users) . " users.\n"; ✅ Verify Everything Works Enable email in config/email-settings.json: