php-imap
php-imap copied to clipboard
Thread
$folders = [ $client->getFolder('INBOX'), ]; $sent = $client->getFolder("[Gmail]/Sent Mail"); $today = Carbon::today(); $yesterday = Carbon::today()->subDays(1); foreach ($folders as $folder) { $messages = $folder->query()->since($yesterday)->from($toEmail)->to($fromEmail)->all()->get(); foreach ($messages as $message) { $emailThreads[] = [ 'from_email' => $message->getFrom()[0]->mail, 'to_email' => $message->getTo()[0]->mail, 'to_name' => $message->getTo()[0]->full, 'from_name' => $message->getFrom()[0]->full, 'subject' => $message->getSubject()[0], 'body' => $message->getHTMLBody(), 'reply_date' => $message->getDate()[0]->toDateTimeString(), 'message_id' => $message->getAttributes()['message_id'][0], 'refrence_id' => isset($message->getAttributes()["references"][0]) ? $message->getAttributes()["references"][0] : '', 'check_attachment' => $message->hasAttachments(), 'attachment' => $message->getAttachments(), 'date' => $message->getDate()->toDate(), ]; } } This is my logic to fetch the emails in the inbox folder I want the whole thread of it to help me to solve this