query($sql); if ($result->num_rows == 0) { redirect(SITE_URL . ADMIN_PATH . '/manage-tickets.php'); } $ticket = $result->fetch_assoc(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $admin_reply = clean_input($_POST['admin_reply']); $new_status = clean_input($_POST['ticket_status']); $admin_id = $_SESSION['admin_id']; if (empty($admin_reply)) { $error = "Reply message is required"; } else { // Update ticket $update_sql = "UPDATE contact_messages SET admin_reply = '$admin_reply', ticket_status = '$new_status', replied_at = NOW(), replied_by = $admin_id WHERE id = $ticket_id"; if ($conn->query($update_sql)) { $success = "Reply sent successfully!"; // Check if this is member or visitor $is_member = !empty($ticket['member_id']); // Send email notification to user $email_subject = "Response to Your Query - Ticket #$ticket_id"; if ($is_member) { // Member email (existing format) $email_message = "

Paid Survey Hub - Support Response

Dear " . htmlspecialchars($ticket['name']) . ",

Thank you for contacting us. We have reviewed your query and here is our response:

Your Message:

" . nl2br(htmlspecialchars($ticket['message'])) . "

Our Response:

" . nl2br($admin_reply) . "

Ticket #$ticket_id - Status: " . ucfirst(str_replace('_', ' ', $new_status)) . "

You can view your tickets anytime by logging in to your account and visiting the 'My Tickets' section.

View My Tickets

If you have any further questions, please don't hesitate to contact us again.

Best regards,
Paid Survey Hub Support Team

"; } else { // Visitor email with respond button $response_link = SITE_URL . "/reply-ticket.php?token=" . $ticket['response_token'] . "&id=" . $ticket_id; $email_message = "

Paid Survey Hub - Support Response

Dear " . htmlspecialchars($ticket['name']) . ",

Thank you for contacting us. We have reviewed your query and here is our response:

Your Message:

" . nl2br(htmlspecialchars($ticket['message'])) . "

Our Response:

" . nl2br($admin_reply) . "

Ticket #$ticket_id - Status: " . ucfirst(str_replace('_', ' ', $new_status)) . "

Have a follow-up question?

Click the button below to respond to this ticket and continue the conversation with our support team.

💬 Respond to Ticket

We hope this resolves your query. If you need further assistance, just click the respond button above.

Best regards,
Paid Survey Hub Support Team

Ticket #$ticket_id

"; } send_email($ticket['email'], $email_subject, $email_message); // Refresh ticket data $result = $conn->query($sql); $ticket = $result->fetch_assoc(); } else { $error = "Failed to send reply. Please try again."; } } } $page_title = 'View Ticket'; include '../includes/header.php'; ?>
← Back to Tickets

Ticket #

'background: #ffc107; color: #000;', 'in_progress' => 'background: #17a2b8; color: #fff;', 'resolved' => 'background: #28a745; color: #fff;', 'closed' => 'background: #6c757d; color: #fff;' ]; $status_text = ucfirst(str_replace('_', ' ', $ticket['ticket_status'])); ?>

Ticket Information

Type:

Member Query Visitor Query

Submitted:

Last Reply:

Contact Details

Name

Email

Member Name

Phone

Member ID

# (View Account)

User Message

Your Previous Reply

This reply will be emailed to
Note: Visitor will receive a "Respond" button in the email to continue the conversation.
Cancel