Unprocessed Email > Make a Ticket - the client it is for, and the contact: one of theirs, the sender made * a contact there first, or nobody. Asked of the email parser (agent/post/email_unprocessed.php), which makes the * ticket from the email as it would any other - its text, attachments and the rest. A sender who is a contact already * (an email that failed) starts picked. */ 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; // A sender who is a contact already starts picked - their client and them $known = $from_email !== '' ? mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_id, contact_client_id FROM contacts LEFT JOIN clients ON client_id = contact_client_id WHERE contact_email = '" . escapeSql($from_email) . "' AND contact_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('contact_client_id') . " ORDER BY contact_primary DESC, contact_id LIMIT 1")) : null; $client_id = intval($known['contact_client_id'] ?? 0); $contact_id = intval($known['contact_id'] ?? 0); ob_start(); ?>