Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mailthief Laravel Package

tightenco/mailthief

MailThief is a fake mailer for Laravel that intercepts outgoing email during tests, letting you inspect recipients, subjects, and message bodies without sending anything. It makes asserting on mail simple, fast, and reliable, with no real SMTP or inbox needed.

View on GitHub
Deep Wiki
Context7

MailThief is a fake mailer for Laravel that intercepts messages sent through the Mail facade and stores them in memory instead of delivering them. It provides a clean, fluent API for inspecting captured mail during tests or local development—recipients, subject, and rendered body—so you can verify your application sends the right emails without touching SMTP.

  • Captures mail sent via Mail::send, Mail::raw, and queued mail
  • Fluent assertions for to/cc/bcc recipients, subject, and body
  • Inspect rendered HTML and plain-text views
  • Zero configuration—hijack the mailer and start asserting
Frequently asked questions about Mailthief
What is tightenco/mailthief and how does it work?
MailThief is a fake mailer for Laravel that rebinds the mailer in the container to an in-memory store, so anything sent through the Mail facade is captured instead of delivered. It registers fluent assertion macros on your test case so you can inspect recipients, subject lines, and rendered bodies. It is strictly a test-time service double and never runs in production.
How do I install MailThief in a Laravel project?
Install it as a dev dependency with composer require --dev tightenco/mailthief, pinned to the exact 0.3.14 release since the package is a dead 0.x line. Laravel auto-discovers the service provider; Lumen needs manual registration plus a MailThief alias in bootstrap/app.php. Then call MailThief::hijack() in your base TestCase setUp() before any mail is sent.
Which Laravel versions does MailThief support?
It targets Laravel 5.1 through 5.4 and Lumen applications that send mail through the Mail facade or the MailThief alias. On Laravel 5.5 and newer you should use the framework's built-in Mail::fake() instead, which covers recipients, subjects, bodies, attachments, and queued mail. Anything outside the legacy range is unsupported.
Does MailThief capture queued mail?
No. Mailables implementing ShouldQueue that are dispatched through database or redis queue drivers never reach the in-memory store, so those assertions silently pass while checking nothing. Audit every existing mail assertion to confirm a message was actually captured. This is the package's highest-risk blind spot and the first thing to verify.
How do I assert on mail sent in a Laravel test with MailThief?
After MailThief::hijack() in setUp(), send mail normally and then chain assertions such as assertSent and assertSentTo, or inspect the last captured message for subject and body. Fluent helpers cover to, cc, and bcc recipients plus subject and rendered content. Prefer anchoring assertions to recipient, subject, view name, or mailable class, because raw body assertions break easily.
Does MailThief work with Lumen?
Yes, with manual setup. Register the MailThief service provider in bootstrap/app.php and add a MailThief alias, since Lumen does not use Laravel's package auto-discovery. After that, hijack the mailer in your test bootstrap exactly as you would in Laravel.
Is MailThief still maintained?
No. The last release was 0.3.14 on 2018-02-10, the line is pre-1.0, and there is no upstream maintainer to escalate to. Pin the exact version, because minor bumps on a 0.x line may include breaking changes and no patch releases will follow. Open a removal ticket tied to your next framework or PHP upgrade so the debt has a name and a date.
Should I use MailThief or Laravel's Mail::fake()?
For Laravel 5.5 and newer, always use the framework's Mail::fake(), which is actively maintained and covers recipients, subjects, bodies, attachments, and queued mail. MailThief only makes sense for legacy 5.1 to 5.4 or Lumen codebases that predate that API. Do not run both at once, since both replace the mailer binding and the last writer wins, producing confusing no-message-found failures.
Does MailThief work with PHP 8 and PHPUnit 8 or later?
Not without changes. It predates typed setUp(): void signatures, so PHPUnit 8 and above throw signature-mismatch fatals. In practice you either pin a legacy PHPUnit and PHP toolchain matching Laravel 5.1 to 5.4, or migrate to Mail::fake() and drop the package.
Can I inspect the rendered HTML and plain-text body of captured mail?
Yes. Each captured message exposes the rendered HTML and the plain-text view, so you can assert on body content when the case genuinely requires it. Keep those assertions narrow, since they break on cosmetic template changes and on to-array internals rather than on real product regressions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections