Unprocessed Email > Add to a Ticket - the ticket it goes on: an open one, or one closed in the last 30 * days. Asked of the email parser (agent/post/email_unprocessed.php), which adds it as it would a reply to the ticket - * a client reply from a contact or CC, else a note only your team sees. The sender can be made a CC on the ticket * first, so it is their reply and they hear back. */ require_once '../../../includes/modal_header.php'; enforceUserPermission('module_support', 2); $row = mailUnprocessedReady() ? mailUnprocessedRow($_GET['id'] ?? 0) : null; if (!$row || $row['email_unprocessed_done_at'] !== null) { echo json_encode(['error' => $row ? 'That email was sorted already.' : "That email isn't there any more."]); exit; } $id = intval($row['email_unprocessed_id']); $from_email = trim((string) $row['email_unprocessed_from_email']); $from_name = trim((string) $row['email_unprocessed_from_name']); $can_add = filter_var($from_email, FILTER_VALIDATE_EMAIL) !== false; // Open tickets, and ones closed lately - the newest first $sql_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_closed_at, ticket_status_name, client_name, contact_name, contact_email FROM tickets LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status LEFT JOIN clients ON client_id = ticket_client_id LEFT JOIN contacts ON contact_id = ticket_contact_id WHERE (ticket_closed_at IS NULL OR ticket_closed_at > NOW() - INTERVAL 30 DAY) " . clientScopeSql('ticket_client_id') . " ORDER BY ticket_closed_at IS NOT NULL, ticket_id DESC LIMIT 2000"); ob_start(); ?>