| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- //error_reporting(E_ERROR | E_PARSE);
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- date_default_timezone_set("Australia/Hobart");
- ini_set("default_charset", "UTF-8");
- mb_internal_encoding("UTF-8");
- require_once 'config.php';
- $cfg = require __DIR__ . '/config.php';
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require_once __DIR__ . '/vendor/autoload.php';
- $cfg = require __DIR__ . '/config.php';
- $dsn = 'mysql:host=' . $cfg['db_host'] . ';dbname=' . $cfg['db_name'] . ';charset=utf8mb4';
- $options = [
- PDO::ATTR_ERRMODE => 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 = <<<HTML
- <p>Hello,</p>
- <p>Your application has reached a new stage: <strong>{$title}</strong></p>
- <p>{$desc}</p>
- <p><a href="{$viewUrl}" class="btn btn-primary">View Application Progress</a></p>
- <p>Kind regards,<br>{$cfg['dev_name']}<br>{$cfg['dev_company']}</p>
- 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");
|