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

$sender_id = $_SESSION['user_id'];
$receiver_id = $_POST['receiver_id'];
$subject = trim($_POST['subject']);
$body = trim($_POST['body']);

$stmt = $conn->prepare("INSERT INTO messages (sender_id, receiver_id, subject, body) VALUES (?, ?, ?, ?)");
$stmt->bind_param("iiss", $sender_id, $receiver_id, $subject, $body);

if ($stmt->execute()) {
    header("Location: ../pages/common/messages/sent.php?success=1");
} else {
    echo "Failed to send message.";
}
