Preview Laravel Mailable's Blade template

1. Use Mailable Preview in Browser

You can create a route to return the Mailable's rendered view:

use App\Mail\RenewableProductNotificationMail;
use Illuminate\Support\Facades\Mail;

Route::get('/test-mail', function () {
    $data = [
        'customerName' => 'John Doe',
        'product' => 'Premium Subscription',
        'expiryDate' => now()->addDays(7)->format('Y-m-d'),
    ];

    return new RenewableProductNotificationMail($data);
});

2. Manually Render the View

If you just want to check the Blade view:

return view('emails.renewable_product_notification', [
    'customerName' => 'John Doe',
    'product' => 'Premium Subscription',
    'expiryDate' => now()->addDays(7)->format('Y-m-d'),
]);

3. Use Mail Preview in Laravel Debugbar (If Installed)

If you have Laravel Debugbar installed, you can log the email instead of sending it:

Mail::to($customerEmail)
    ->send(new RenewableProductNotificationMail($data));

\Log::info((new RenewableProductNotificationMail($data))->render());

4. Use Laravel Mail Fake for Testing

In a test, you can capture the email and view the HTML:

use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
use App\Mail\RenewableProductNotificationMail;

class MailTest extends TestCase
{
    public function test_mail_view()
    {
        Mail::fake();

        $data = ['customerName' => 'John Doe', 'product' => 'Premium Subscription'];
        Mail::to('[email protected]')->send(new RenewableProductNotificationMail($data));

        Mail::assertSent(RenewableProductNotificationMail::class, function ($mail) {
            echo $mail->render(); // View email in console
            return true;
        });
    }
}