// Last attempt: if we still don't have a valid recipient or have a wrong one, try a direct lookup of the email from the notification body if (empty($recipient) || $recipient === 'firat@kirmizi.gen.tr') { if (preg_match('/customer_id=(\d+)/', $email['message'], $matches)) { $customerId = $matches[1]; $lookupStmt = $this->db->prepare("SELECT email FROM customers WHERE customer_id = ? AND deleted = 0"); $lookupStmt->execute([$customerId]); $lookupEmail = $lookupStmt->fetchColumn(); if ($lookupEmail) { $recipient = $lookupEmail; error_log("Used direct database lookup from message body: {$recipient}"); // Update the notification record for future sends $updateStmt = $this->db->prepare("UPDATE notifications_queue SET email_to = ? WHERE id = ?"); $updateStmt->execute([$recipient, $email['id']]); } } else if (!empty($email['user_id'])) { // Try direct user lookup as last resort $userStmt = $this->db->prepare("SELECT email FROM users WHERE user_id = ? AND deleted = 0"); $userStmt->execute([$email['user_id']]); $userEmail = $userStmt->fetchColumn(); if ($userEmail && $userEmail !== 'firat@kirmizi.gen.tr') { $recipient = $userEmail; error_log("Last resort: Used user's email from database: {$recipient}"); } } } GarageSync