$sender, 'message' => $message, 'timestamp' => date('Y-m-d H:i:s') ]; $currentMessages = json_decode(file_get_contents($conversationFilePath), true) ?: []; $currentMessages[] = $messageEntry; file_put_contents($conversationFilePath, json_encode($currentMessages)); // Send email notification if receiver has an email $receiverProfilePath = "profiles/{$receiver}.txt"; if (file_exists($receiverProfilePath)) { $receiverProfile = json_decode(file_get_contents($receiverProfilePath), true); if (!empty($receiverProfile['email'])) { $to = $receiverProfile['email']; $subject = "New Message from Profile [{$sender}]"; $body = "You have received a new message from Profile [{$sender}]:\n\n{$message}"; $headers = "From: no-reply@yourwebsite.com"; mail($to, $subject, $body, $headers); } } } echo "
"; echo ""; echo " "; echo ""; echo ""; } else { echo "Incorrect password."; } } else { echo "Sender profile not found."; } } function deleteMessages($profile) { $files = glob("profiles/{$profile}_*.txt"); foreach ($files as $file) { unlink($file); } $files = glob("profiles/*_{$profile}.txt"); foreach ($files as $file) { unlink($file); } } ?>