Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ottaviane's avatar

How to use Webklex with Laravel

Hi all, I need to read from a imap server only recent email, for example only from 3 days ago, but with Webklex I don't know how to obtain it. I made this controller but it returns an error of overflow memory: "message: Allowed memory size of 134217728 bytes exhausted (tried to allocate 11833520 bytes)". I think it's because messages are too many. This is my controller:

<?php

namespace App\Http\Controllers\Mailer;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Webklex\IMAP\Facades\Client;

class MailerController extends Controller
{
    public function read(Request $req){
        $client = Client::account('default');

        //Connect to the IMAP Server
        $client->connect();

        //Get all Mailboxes
        $folders = $client->getFolders();
        $messages = [];
        //Loop through every Mailbox
        foreach($folders as $folder){
            $messages[] = $folder->messages()->all()->get(); 
        }
        return response()->json([
            'folders' => $folders,
            'messages' => $messages
        ],200);
    }
}

Is there any way to read only latest messages? Does anyone know where to find good documentation on this library? Thank you. Bye.

0 likes
0 replies

Please or to participate in this conversation.