Build Laravel mailables with react.email.
You can install the package via composer:
composer require spectate/laravel-react-email
Next up, install the required NPM packages:
npm i -D typescript react react-email @react-email/components @react-email/render @types/react @types/node
You can publish the config file with:
php artisan vendor:publish --tag="react-email-config"
If you run composer install
during deployments, this way you will automatically regenerate the React Email templates on each deploy.
To enable this, add the following to your composer.json
file:
{
"post-install-cmd": [
"@php artisan react-email:build"
]
}
Create your first React Email template:
php artisan make:react-email MyFirstEmail
You can run the React Email dev server to preview your templates:
php artisan react-email:dev
This will start the dev server and watch for changes in your templates.
Next up, edit the files in resources/views/react-emails
and see the changes in your browser.
To support variables in the compiled Blade templates, you can use the following syntax in your React Email templates:
export default function MyEmail() {
return (
<Html>
Hello, $$name$$!
</Html>
);
}
This will be compiled to the following Blade template:
Hello, {{ $name }}!
By default, on local development environments, the React Email templates are rendered on-the-fly for every send. This can be disabled by setting the REACT_EMAIL_HOT_RELOAD
environment variable to false
.
You can build the React Email templates to HTML using the react-email:build
command:
php artisan react-email:build
This will build all the templates and output them to resources/views/vendor/react-email
.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.