1. Go to this page and download the library: Download spatie/laravel-mail-preview library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return [
/*
* By default, the overlay will only be shown and mail will only be stored
* when the application is in debug mode.
*/
'enabled' => env('APP_DEBUG', false),
/*
* All mails will be stored in the given directory.
*/
'storage_path' => storage_path('email-previews'),
/*
* This option determines how long generated preview files will be kept.
*/
'maximum_lifetime_in_seconds' => 60,
/*
* When enabled, a link to mail will be added to the response
* every time a mail is sent.
*/
'show_link_to_preview' => true,
/*
* Determines how long the preview pop up should remain visible.
*
* Set this to `false` if the popup should stay visible.
*/
'popup_timeout_in_seconds' => 8,
/**
* Determines the date format used for the file names.
*
* The default 'u' stands for microseconds.
*/
'filename_date_format' => 'u',
];
// in a test
Artisan::call(CommandThatSendsMail::class);
Spatie\MailPreview\Facades\SentMails::assertLastContains('something in your mail');
namespace App\Mail;
use Illuminate\Mail\Mailable;
class MyNewSongMailable extends Mailable
{
public function build()
{
$this
->to('[email protected]')
->cc('[email protected]')
->bcc('[email protected]')
->subject('Here comes the sun')
->html("It's been a long cold lonely winter");
}
}
Mail::send(new MyNewSongMailable());
use Spatie\MailPreview\Facades\SentMails;
use \Spatie\MailPreview\SentMails\SentMail;
SentMails::assertSent(fn (SentMail $mail) => $mail->bodyContains('winter')); // will pass
SentMails::assertSent(fn (SentMail $mail) => $mail->bodyContains('spring')); // will not pass