DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Preview and Test Laravel Email Before Sending

Preview Laravel mailables with render() or a protected browser route, test content and dispatch separately, and capture development mail without sending it to real users.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To preview a Laravel mailable without sending it, call render() for its HTML or return the mailable from a development-only route to view it in a browser. To test that your application asks Laravel to send the right message without contacting real recipients, use Mail::fake() and send assertions. These methods cover different things: rendered content, dispatch behavior, and captured transport output each need their own check.

Choose the right way to inspect a Laravel email

Need Use What it checks
Get the evaluated HTML in code render() The HTML produced by a mailable for the data you supplied.
See the design in a browser Return the mailable from a protected development route How the rendered message looks as a browser response; it does not send to an email address.
Check important copy or values HTML and text mailable assertions Whether expected content is present or absent in the relevant representation.
Check application dispatch safely Mail::fake() and send assertions Whether the application requested that Laravel send the expected mailable.
Inspect a message passed through a development transport A log driver or local SMTP catcher such as Mailpit What the configured development transport captured.

These checks are complementary. A browser preview does not show that application code dispatched the message; a send assertion does not assess the design; and a locally captured message does not establish inbox placement or production deliverability.

As an Amazon Associate I earn from qualifying purchases.

Render the mailable to an HTML string

Use render() when you need the evaluated HTML in PHP—for example, to debug the output for specific view data or pass it to another local inspection step. Create a mailable with php artisan make:mail if you do not already have one; its content definition selects the Blade view or Markdown template and the data supplied to it. Laravel’s mail documentation describes both mailables and rendering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$html = (new InvoicePaid($invoice))->render();

This renders the mailable; it does not, by itself, deliver it to a recipient. Use representative fixture data when inspecting output, especially if the real message contains account or invoice details.

Preview a mailable in a browser

For a quick visual check, a route can return a mailable object. Laravel renders it as the HTTP response, so you can inspect the layout without sending it to an email address.

Route::get('/dev/mail-preview', function () {
    $invoice = Invoice::factory()->make();

    return new InvoicePaid($invoice);
});

This is an illustrative pattern: adapt the factory and route to your application. Keep preview routes out of public production access. Use non-sensitive sample data and restrict access to authorized developers; a route that renders real invoices or account messages can expose their contents to anyone who can reach it.

Test HTML and text content

Use mailable assertions to protect important content in automated tests. For example, check the HTML heading and a value in the plain-text alternative:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$mailable = new InvoicePaid($invoice);

$mailable->assertSeeInHtml('Invoice Paid');
$mailable->assertSeeInText($invoice->number);

Laravel’s mail documentation explains content assertions. Markdown mailables produce responsive HTML and automatically generate a plain-text counterpart, so assert against whichever representation matters to recipients rather than assuming an HTML check covers both.

Test sending without contacting real recipients

Content checks and application dispatch checks answer separate questions. In a test of the behavior that triggers an email, fake the mailer before exercising that behavior, then assert that Laravel was asked to send the expected mailable.

Mail::fake();

// Trigger the application action that sends the message.

Mail::assertSent(InvoicePaid::class);

Use the assertion supported by your installed Laravel version and test framework. Where recipient identity matters, add the available recipient-specific check. Laravel recommends separating tests of mailable content from tests of the code that sends it; see the mail testing documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect a message captured by a local mail transport

A catcher is useful when you need to inspect the message as it passes through the configured development transport rather than only the rendered view. Laravel supports a log mail driver, which writes messages to application logs. For local SMTP capture, Laravel Sail’s documented default Compose configuration includes Mailpit: SMTP host mailpit, port 1025, and browser interface at http://localhost:8025. Sail also documents Mailtrap Local with default host mailtrap-local and port 3535. See the Sail documentation for those defaults.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Those settings apply to the documented Sail setup, not to every Laravel project. Check the running Compose services, .env, and config/mail.php before relying on a host or port; other projects may use a different catcher or transport.

Account for attachments and email-client differences

A browser response is not a full email-client test. Laravel 8.x documentation specifically notes that inline attachments are not rendered in its browser preview and recommends an email testing application for mailables that use them. Because that note is version-specific, check the documentation for your installed Laravel version and use a captured-message workflow when inline assets matter. See the Laravel 8.x mail documentation.

Likewise, a local catcher confirms what reached that catcher, not whether a production message will land in an inbox, avoid spam, or look identical across mailbox clients. Treat rendering, content assertions, dispatch assertions, and client or delivery evaluation as distinct checks.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.