Architecture

Laravel Inbound Email: Turn Customer Replies into Tickets

By Lara Dashboard 1 view
Laravel Inbound Email: Turn Customer Replies into Tickets
Laravel inbound email is the missing half of most support setups. Your app sends a ticket notification, the customer hits reply, and the answer lands in a shared inbox that nobody links back to the ticket. Lara Dashboard closes that loop in core: it polls an IMAP mailbox on a schedule, stores each message, strips the quoted text, and hands it to a handler that turns it into a record, such as a reply on the right ticket.
Disclosure: Lara Dashboard is our own open-source, MIT-licensed Laravel CMS and admin, so this is our guide to our own feature. Every class, command and column name below comes from the develop branch on GitHub as of December 2026 (v1.5.0, Laravel 13, PHP 8.3+). Where we describe the CRM module's ticket handler, we rely on the implementation notes in docs/INBOUND_EMAIL_IMPLEMENTATION.md, because the CRM module is not in the public repo.

Quick answer: IMAP polling, a parser and pluggable handlers

Here is the whole pipeline in one list. The rest of the post explains each step and where it can trip you up.
  1. You add an inbound connection (IMAP host, port, encryption, username, password, folder) in the admin.
  2. The scheduler runs email:process-inbound every five minutes, and each connection is polled when its own interval is due.
  3. New messages are saved to the inbound_emails table, skipping any Message-ID already imported.
  4. A parser strips quoted history and signatures into a clean body.
  5. Registered handlers are asked, in priority order, whether they can handle the message. The first match creates the record.
  6. Anything unmatched or broken is marked failed and shows up in the daily briefing.
If you want the bigger picture of why forms, CRM and tickets belong in one app, read forms, CRM and support tickets in one Laravel stack first.

Laravel itself does not receive email, so you need a pipeline

Laravel's mail layer is built for sending. There is no built-in mailbox that receives replies, unlike Rails, which ships Action Mailbox. So every Laravel team that wants email-to-ticket ends up choosing between two designs.
Provider webhooks. Services such as Postmark, Mailgun and SendGrid can receive mail for a domain and POST it to your app. It is fast and needs no polling, but you depend on that provider and its inbound pricing.
IMAP polling. Your app logs into an existing mailbox, such as support@yourcompany.com, and reads new messages on a schedule. It works with almost any mail host and needs no DNS changes. The cost is a delay of a few minutes and the PHP IMAP extension.
Lara Dashboard core takes the IMAP route. That fits agencies and small SaaS teams that already have a support mailbox and do not want another vendor in the chain.

Setting up a connection takes one form and one test

Inbound connections live under the email settings, on the Inbound tab next to outbound connections, templates and notifications. The screens are guarded by the settings permission, so only admins who can manage settings can add a mailbox.
Each connection stores the fields you would expect, plus a few that matter in production:
FieldDefaultWhy it matters
imap_port / imap_encryption993 / sslUse SSL on 993 unless your host says otherwise.
imap_passwordnoneStored with Laravel's encrypted cast and hidden from JSON output.
imap_folderINBOXPoint it at a dedicated folder if the mailbox is shared.
imap_validate_certtrueLeave it on. Turn it off only for a self-signed test server.
mark_as_readtrueStops the same message being fetched as unread again.
delete_after_processingfalseKeep it off until you trust the pipeline.
fetch_limit50Messages per batch, so one busy run cannot time out.
polling_interval5 minutesHow often this mailbox is checked.
Each connection row has Test and Process now buttons. Test opens the IMAP session and reports errors without importing anything. Process now runs one fetch and shows how many messages were fetched, processed and failed. Use both before you rely on the scheduler.
The connection also records last_checked_at, last_check_status and last_check_message, so a broken password shows up on the list screen instead of failing silently.

The scheduler does the polling, so cron must be running

Lara Dashboard registers the command in app/Console/Kernel.php. It runs every five minutes, without overlapping, in the background, and appends its output to storage/logs/inbound-email.log. Each run only polls connections whose own interval has passed.
That means one thing on your server: the standard Laravel cron entry that calls php artisan schedule:run every minute. If you skipped it, nothing is fetched. The Laravel scheduling docs show the exact line, and our hosting and deploy guide covers where it goes on a VPS or a managed host.
You can also run the command by hand. These are the options in the current signature:
php artisan email:process-inbound polls connections that are due.
php artisan email:process-inbound --all polls every active connection, ignoring intervals.
php artisan email:process-inbound --connection=1 polls one connection by ID or UUID.
php artisan email:process-inbound --test tests the connections without importing.
php artisan email:process-inbound --recent --days=7 fetches recent mail instead of unread only, which helps with "All Mail" style folders.

Replies thread onto tickets by headers first, subject second

Every message is stored with its message_id, in_reply_to and references headers, the sender, the subject, plain and HTML bodies, and attachment metadata. Before saving, the processor drops any message whose Message-ID is already in the table, so a re-run does not create duplicates.
Then EmailParserService builds body_parsed. It strips common "On … wrote:" lines, Gmail and Outlook quote blocks, lines starting with >, and common signature markers. That is what you want on a ticket: the customer's new words, not the whole thread again.
According to our implementation notes, the CRM module's TicketEmailHandler matches a message to a ticket in this order: the In-Reply-To header against stored reply message IDs, then every ID in the References header, then a ticket number in the subject, such as [Ticket #12345] or Re: [#12345]. When it matches, it creates a ticket reply. Header matching is the reliable path. Subject matching is the fallback for mail clients that drop headers. You can see how tickets fit into the CRM in our CRM module tour.

Custom handlers turn email into any record you need

The ticket handler is one example of a general contract. Any module can implement App\Contracts\InboundEmailHandlerInterface, which has five methods:
  • getHandlerType() returns a unique key, such as bookings.reply.
  • getName() returns a display name.
  • getPriority() returns a number. Lower numbers are asked first.
  • canHandle() looks at the stored email and returns true or false.
  • handle() creates your record and returns a result object.
The result is an InboundEmailHandlerResult. Return success() with the model class and ID you created, and the processor stores them on the email row as handler_model_type and handler_model_id. That gives you an audit link from every stored message to the record it produced.
Register the handler from your module's service provider, inside $this->app->booted(), by calling registerHandler() on the InboundEmailProcessor singleton. Because it lives in the module, the handler disappears when the module is disabled. If you have not built a module yet, start with build a Laravel module step by step.
A good first custom handler is "new ticket from unmatched mail". Out of the box, a message that no handler accepts is marked failed with "No handler matched this email". If you want a fresh email to support@ to open a new ticket, that is a handler you write, with a high priority number so it runs after the reply matcher.

Hooks let you watch the pipeline without changing it

The processor fires four actions from the InboundEmailHook enum: BEFORE_PROCESS, AFTER_PROCESS, PROCESS_FAILED and UNMATCHED. You attach to them with Hook::addAction(), the same system we explain in Laravel hooks and filters in Lara Dashboard.
Use them for side effects: alert a Slack channel when processing fails, count unmatched mail per sender, or notify the ticket assignee after a reply lands. Keep record creation in handlers, where the result is tracked.

Gotchas we found reading the code

Pass the argument count. Hook::addAction() defaults to one accepted argument. AFTER_PROCESS passes the email, the handler and the result, so register it with accepted_args set to 3, or your callback only gets the email.
BEFORE_PROCESS cannot cancel. The enum's comment says a listener can return false to skip processing. In the current processor it is fired with doAction(), and the return value is ignored. To filter mail, do it in a handler's canHandle().
Retries are code-only. InboundEmailProcessor::reprocessEmail() resets a failed message and runs it again, but there is no button for it yet. Use tinker or a small command of your own.
Attachments are metadata only. The importer records file name, type, size and part number. It does not save the files. If tickets need attachments, your handler must fetch and store them.
The polling query is MySQL-flavoured. The "due for polling" scope uses DATE_SUB(NOW(), INTERVAL …). On PostgreSQL or SQLite, test it first, or schedule --all instead.
The IMAP extension is not in PHP core any more. The code calls imap_open() directly. Since PHP 8.4, the extension lives in PECL, as the PHP manual's installation page explains. Check that your host or Docker image ships it before launch.

When this is not the right tool

IMAP polling with a username and password is simple, and simple has limits. Be honest about these before you promise a client email-to-ticket.
Microsoft 365 mailboxes. Microsoft has turned off basic authentication for IMAP in Exchange Online, as its deprecation notice explains. The connection form uses a password, not OAuth, so plan on a different mailbox or a forwarding rule.
Gmail and Google Workspace. A normal password will not work. Google requires an app password, which needs 2-Step Verification, and Workspace admins can block that.
Near real-time support. Replies arrive every few minutes, not instantly. If seconds matter, a provider webhook is the better design.
High volume or many channels. If you run SLAs across email, chat and phone with a large team, a dedicated helpdesk will serve you better. This pipeline is for teams that want support next to their CMS and CRM, not a contact-centre platform.
No CRM module. Core gives you the pipeline and the contract. Ticket threading comes from the CRM module or from a handler you write.

Self-check before you switch it on

  1. The PHP IMAP extension is installed on every server that runs the scheduler.
  2. The Laravel cron entry is running schedule:run every minute.
  3. The mailbox accepts password or app-password IMAP logins.
  4. Test passes on the connection, and Process now fetches a sample message.
  5. Certificate validation is on, and delete after processing is off for the first weeks.
  6. Outgoing ticket emails keep a stable Message-ID or a ticket number in the subject.
  7. You decided what happens to unmatched mail: fail it, or open a new ticket with a handler.
  8. Someone owns the daily briefing items for failed and pending inbound mail.
  9. You know how to rerun a failed message from tinker.
  10. Attachment needs are clear, because files are not saved by default.

Verdict

Laravel inbound email does not have to mean a third-party helpdesk or a hand-rolled IMAP script. In Lara Dashboard the pipeline is already in core: encrypted connections, a scheduled command, duplicate protection, quote stripping, priority-ordered handlers, hooks and briefing alerts. You add the mailbox, make sure cron runs, and either use the CRM handler or write your own.
Know the limits: password-based IMAP, a few minutes of delay, and attachments you store yourself. If those fit, try Lara Dashboard, connect a test mailbox, and reply to your first ticket from your phone.

FAQ

Does Laravel have built-in inbound email?

No. Laravel's mail features send email. To receive it you either accept provider webhooks or poll a mailbox over IMAP. Lara Dashboard adds IMAP polling in core.

How often does Lara Dashboard check the mailbox?

The scheduler runs the inbound command every five minutes. Each connection also has its own polling interval, five minutes by default, and is only checked when that interval has passed.

Will the same email create two ticket replies?

Not on a normal re-run. The processor skips any message whose Message-ID is already stored, and messages are marked as read after fetching by default.

Can inbound email create new tickets, not just replies?

Yes, with a handler. Out of the box, mail that no handler accepts is marked failed. Write a low-priority handler that opens a ticket for unmatched mail sent to your support address.

Does it work with Gmail or Microsoft 365?

Gmail works with an app password. Microsoft 365 has turned off basic authentication for IMAP, and the connection uses a password, so use another mailbox or forward mail to one that supports IMAP logins.

Are attachments saved?

Only their metadata: file name, type, size and part number. If you need the files on tickets, fetch and store them in your handler.
Laravel CMS Open source Admin Panel Module Architecture

Try Lara Dashboard for Free

Explore every feature live — no sign-up required.

Launch Live Demo