PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]; try { $pdo = new PDO($dsn, $cfg['db_username'], $cfg['db_password'], $options); } catch (PDOException $e) { exit('Database connection failed: ' . $e->getMessage()); } $app_id = $_POST['application_id']; $title = $_POST['title']; $desc = $_POST['description']; // Save stage $stmt = $pdo->prepare("INSERT INTO application_stages (application_id, title, description) VALUES (?, ?, ?)"); $stmt->execute([$app_id, $title, $desc]); // Fetch client email $stmt = $pdo->prepare("SELECT client_email FROM applications WHERE id = ?"); $stmt->execute([$app_id]); $email = $stmt->fetchColumn(); function sendStageEmail($to, $title, $desc, $viewUrl) { global $cfg; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = $cfg['smtp_host']; $mail->SMTPAuth = true; $mail->Username = $cfg['smtp_username']; $mail->Password = $cfg['smtp_password']; $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; $mail->Port = $cfg['smtp_port']; $mail->setFrom($cfg['from_address'], $cfg['dev_company']); $mail->addAddress($to); $mail->isHTML(true); $subject = "Council Application Progress Update"; $html = <<Hello,

Your application has reached a new stage: {$title}

{$desc}

View Application Progress

Kind regards,
{$cfg['dev_name']}
{$cfg['dev_company']}

HTML; $mail->Subject = $subject; $mail->Body = $html; $mail->AltBody = "New update: $title\n\n$desc\n\nView: $viewUrl"; $mail->send(); } // Redirect back to admin dashboard header("Location: admin_dashboard.php");