<?php
session_start();
include('../../../includes/config.php');

$user_id = $_SESSION['user_id'];
$messages = $conn->query("SELECT m.*, CONCAT(u.first_name, ' ', u.last_name) AS receiver_name 
                          FROM messages m 
                          JOIN users u ON m.receiver_id = u.id 
                          WHERE sender_id = $user_id 
                          ORDER BY sent_at DESC");
?>

<h2>Sent Messages</h2>
<?php while ($msg = $messages->fetch_assoc()): ?>
    <div>
        <strong><?= htmlspecialchars($msg['subject']) ?></strong> 
        to <?= htmlspecialchars($msg['receiver_name']) ?>
    </div>
<?php endwhile; ?>
