Download the PHP package themsaid/laravel-mail-preview without Composer
On this page you can find all versions of the php package themsaid/laravel-mail-preview. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download themsaid/laravel-mail-preview
More information about themsaid/laravel-mail-preview
Files in themsaid/laravel-mail-preview
Package laravel-mail-preview
Short Description A mail driver to quickly preview mail
License MIT
Homepage https://github.com/themsaid/laravel-preview-mail-driver
Informations about the package laravel-mail-preview
A mail driver to quickly preview mail
This package can display a small overlay whenever a mail is sent. The overlay contains a link to the mail that was just sent.
This can be handy when testing out emails in a local environment.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
Configuring the mail transport
This package contains a mail transport called preview
. We recommend to only use this transport in non-production environments. To use the preview
transport, change the mailers.smtp.transport
to preview
in your config/mail.php
file:
Registering the preview middleware route
The package can display a link to sent mails whenever they are sent. To use this feature, you must add the Spatie\MailPreview\Http\Middleware\AddMailPreviewOverlayToResponse
middleware to the web
middleware group in your kernel.
You must also add the mailPreview
to your routes file. Typically, the routes file will be located at routes/web.php
.
This will register a route to display sent mails at /spatie-mail-preview
. To customize the URL, pass the URL you want to the macro.
Publishing the config file
Optionally, you can publish the config file with:
This is the content of the config file that will be published at config/mail-preview.php
:
Publishing the views
Optionally, you can publish the views that render the preview overlay and the mail itself.
You can modify the views that will be published at resources/views/vendor/mail-preview
to your liking.
Usage
Everytime an email is sent, an .html
and .eml
file will be saved in the directory specified in the storage_path
of the mail-preview
config file. The name includes the first recipient and the subject:
You can open the .html
file in a web browser. The .eml
file in your default email client to have a realistic look
of the final output.
Preview in a web browser
When you open the .html
file in a web browser you'll be able to see how your email will look.
At the beginning of the generated file you'll find an HTML comment with all the message info:
Events
Whenever a mail is stored on disk, the Spatie\MailPreview\Events\MailStoredEvent
will be fired. It has three public properties:
message
: an instance ofSwift_Mime_SimpleMessage
pathToHtmlVersion
: the path to the html version of the sent mailpathToEmlVersion
: the path to the email version of the sent mail
Making assertions against sent mails
Currently, using Laravel's Mail::fake
you cannot make any assertions against the content of a mail, as the using the fake will not render the mail.
The SentMails
facade provided this package does allow you to make asserts against the content.
This allows you to make assertions on the content of a mail, without having the mailable in scope.
Let's explain other available assertions method using this mailable as example.
In your code you can send that mailable with:
In your tests you can assert that the mail was sent using the assertSent
function. You should pass a callable to assertSent
which will get an instance of SentMail
to it. Each sent mail will be passed to the callable. If the callable returns true
the assertions passes.
You can use as many assertion methods on the SentMail
as you like.
The Spatie\MailPreview\Facades\SentMails
has the following assertions methods:
assertCount(int $expectedCount)
: assert how many mails were sentassertLastContains(string $expectedSubstring)
: assert that the body of the last sent mail contains a given substringassertSent($findMailCallable, int $expectedCount = 1)
: explained aboveassertTimesSent(int $expectedCount, Closure $findMail)
assertNotSent(Closure $findMail)
Additionally, the Spatie\MailPreview\Facades\SentMails
has these methods:
all
: returns an array of sent mails. Each item will be an instance ofsentMail
count()
: returns the amount of mails sentlast
: returns an instance ofSentMail
for the last sent mail. If no mail was sentnull
will be returned.lastContains
: returnstrue
if the body of the last sent mail contains the given substringtimesSent($findMailCallable)
: returns the amount of mails the were sent and that passed the given callable
The sentMail
class provides these assertions:
assertSubjectContains($expectedSubstring)
assertFrom($expectedAddress)
assertTo$expectedAddress)
assertCc($expectedAddress)
assertBcc($expectedAddress)
assertContains($substring)
: will pass if the body of the mail contains the substring
Additionally, sentMail
contains these methods:
subject()
: return the body of a mailto()
: returns all to recipients as an arraycc()
: returns all cc recipients as an arraybcc()
: returns all bcc recipients as an arraybody()
: returns the body of a mailsubjectContains)
: returns a booleanhasFrom($expectedAddress)
: return a booleanhasTo($expectedAddress)
: return a booleanhasCc($expectedAddress)
: return a booleanhasBcc($expectedAddress)
: return a boolean
Changelog
Please see CHANGELOG for more information on what has changed recently.
UPGRADING
Please see UPGRADING for what to do to switch over from themsaid/laravel-mail-preview
, and how to upgrade to newer major versions.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Freek Van der Herten
- Mohamed Said
- All Contributors
The initial version of this package was created by Mohamed Said, who graciously entrusted this package to us at Spatie.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-mail-preview with dependencies
illuminate/filesystem Version ^10.0|^11.0
illuminate/mail Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
spatie/laravel-package-tools Version ^1.11