TaskHusky Posted Friday at 08:35 PM Share Posted Friday at 08:35 PM I'm trying to achieve a support ticket reminder setup. If a ticket within the sales department is in the status of Answered for 3 days or longer, I want to trigger another Supply Reply email reminding the client that the ticket is still needing a reply. The following script is what I have; however, it doesn't seem to be working in my tests. What is wrong with the current code? <?php use WHMCS\Database\Capsule; // Require the init.php file to access WHMCS functions require_once dirname(__FILE__) . '/../../init.php'; // Set time threshold (72 hours in seconds) $timeThreshold = 72 * 60 * 60; $currentTime = time(); // Get tickets that meet our criteria $tickets = Capsule::table('tbltickets') ->where('department', '=', 1) // Sales department ->where('status', '=', 'Answered') ->where('clientunread', '=', 1) ->get(); foreach ($tickets as $ticket) { // Get the last reply timestamp $lastReply = Capsule::table('tblticketreplies') ->where('tid', '=', $ticket->id) ->orderBy('date', 'desc') ->first(); $lastReplyTime = strtotime($lastReply ? $lastReply->date : $ticket->date); $hoursSinceReply = ($currentTime - $lastReplyTime) / 3600; // Check if it's time to send a reminder (every 72 hours) if ($hoursSinceReply >= 72 && ($hoursSinceReply % 72) < 1) { // Send reminder email $client = localAPI('GetClientsDetails', array('clientid' => $ticket->userid)); $merge_fields = array( 'ticket_id' => $ticket->tid, 'ticket_subject' => $ticket->title, 'client_name' => $client['client_name'], ); sendMessage( 'Support Ticket Reply', // Email template name $ticket->userid, // Client ID $merge_fields // Merge fields ); // Log the reminder logActivity("Sent reminder for Ticket #" . $ticket->tid . " to client #" . $ticket->userid); } } 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.