0.2.0 • Published 9 months ago

@j4mie/react-email v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

React email for Laravel

This package allows you to easily send React email emails with Laravel.

Install

composer require maantje/react-email
yarn add @j4mie/react-email

Usage

Install React email (automatic, manual).

Create an email in the emails directory e.g. new-user.tsx, make sure the component is the default export.

import { Html } from '@react-email/html';
import { Text } from '@react-email/text';
import * as React from 'react';

export default function Email({ user }) {
    return (
        <Html>
            <Text>Hello, {user.name}</Text>
        </Html>
    );
}

Set up the email directory in your Laravel .env.

REACT_EMAIL_DIRECTORY="/my/absolute/path/to/react-email-starter/emails/"

Create a Laravel mailable.

php artisan make:mail NewUser

Extend from ReactMailable instead of Mailable.

use App\Models\User;
use Maantje\ReactEmail\ReactMailable;

class NewUser extends ReactMailable
{
    public function __construct(public User $user) 
    {
        // public properties will be passed as props to the React email component
        // Alternatively use the with property of content
    }
    
    public function envelope()
    {
        return new Envelope(
            subject: 'New User',
        );
    }

    public function content()
    {
        return new Content(
            view: 'new-user', // name of the component file without extension
        );
    }
}

Testing

./vendor/bin/pest

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

0.2.0

9 months ago

0.1.0

1 year ago