<?php
require_once './includes/config.php'; // Database connection

function logCommunication($type, $recipient, $subject, $message, $status, $errorMessage = null) {
    global $pdo;

    try {
        $stmt = $pdo->prepare("
            INSERT INTO communication_logs (type, recipient, subject, message, status, error_message)
            VALUES (:type, :recipient, :subject, :message, :status, :error_message)
        ");
        $stmt->execute([
            'type' => $type,
            'recipient' => $recipient,
            'subject' => $subject,
            'message' => $message,
            'status' => $status,
            'error_message' => $errorMessage
        ]);
        return true;
    } catch (PDOException $e) {
        error_log("Failed to log communication: " . $e->getMessage());
        return false;
    }
}
?>