use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Redis; public function send(Request $request) { $body = $request->input('body'); $to = $request->input('to'); $from = auth()->user()->name; $encrypted = Crypt::encryptString($body); // Store in DB or file $id = uniqid("msg_", true); file_put_contents(storage_path("imail/{$to}/{$id}.msg"), $encrypted); // Store metadata in Redis Redis::hmset("imail:meta:{$id}", [ 'from' => $from, 'to' => $to, 'subject' => $request->input('subject', ''), 'created_at' => now(), 'status' => 'unread', ]); return response()->json(['status' => 'sent', 'id' => $id]); } Read Controller php Copy code use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Redis; public function read($id) { // Load encrypted body $encrypted = file_get_contents(storage_path("imail/" . auth()->user()->name . "/{$id}.msg")); $decrypted = Crypt::decryptString($encrypted); // Mark as read Redis::hset("imail:meta:{$id}", 'status', 'read'); return response()->json([ 'body' => $decrypted, 'meta' => Redis::hgetall("imail:meta:{$id}") ]); }