$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 "

Messages for Profile [{$sender}]

"; if (empty($receiver)) { echo "
"; echo ""; echo ""; echo ""; echo "
"; echo ""; echo "
"; } else { $currentMessages = json_decode(file_get_contents($conversationFilePath), true) ?: []; foreach ($currentMessages as $msg) { echo "
"; echo "
Profile [{$msg['sender']}]
"; echo "
{$msg['timestamp']}
"; echo "
{$msg['message']}
"; echo "
"; } echo "
"; echo ""; echo ""; echo ""; echo "
"; echo ""; echo "
"; } echo ""; echo "

Use the bottom form with a different profile code than the one loaded at the moment.

"; 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); } } ?> Send/Check Messages