PHP code example of mscode-pl / laravel-react-email

1. Go to this page and download the library: Download mscode-pl/laravel-react-email 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/ */

    

mscode-pl / laravel-react-email example snippets


use MsCodePL\LaravelReactEmail\ReactMailable;
use Illuminate\Mail\Mailables\{Content, Envelope};

class WelcomeEmail extends ReactMailable
{
    public function __construct(
        public string $userName,
        public string $activationUrl,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Welcome!');
    }

    public function content(): Content
    {
        return new Content(
            html: 'react-email.welcome-email',
            text: 'react-email.welcome-email-text',
        );
    }
}

Mail::to($user)->send(
    new WelcomeEmail(
        userName: $user->name,
        activationUrl: route('activate', $user->activation_token),
    )
);

return [
    // Source TSX templates
    'path' => env('REACT_EMAIL_PATH', resource_path('react-email')),

    // Compiled Blade output
    'build_path' => env('REACT_EMAIL_BUILD_PATH', resource_path('views/react-email')),
];
bash
php artisan vendor:publish --provider="MsCodePL\LaravelReactEmail\LaravelReactEmailServiceProvider" --tag="react-email-config"
bash
php artisan make:react-email WelcomeEmail
bash
php artisan react-email:build
tsx
export default function InvoiceEmail({
    invoiceNumber = '$$invoiceNumber$$',
    dueDate       = '$$dueDate$$',
}) {
    return (
        <Html>
            <Text>Invoice #$$invoiceNumber$$</Text>
            <Text>Due: $$dueDate$$</Text>
        </Html>
    );
}
tsx
import { blade } from '@mscode-pl/laravel-react-email';

export default function OrderEmail({
    subtotal = blade.number('subtotal'),
    total    = blade.number('total'),
}) {
    return (
        <Html>
            <Text>Subtotal: {subtotal.toFixed(2)} PLN</Text>
            <Text>Total: {total.toFixed(2)} PLN</Text>
        </Html>
    );
}
tsx
import { BladeForEach } from '@mscode-pl/laravel-react-email';

export default function OrderEmail() {
    return (
        <Html>
            <Text>Your items:</Text>
            <BladeForEach items="items">
                <Section>
                    <Text>$$item.name$$ × $$item.quantity$$ — $$item.price$$ PLN</Text>
                </Section>
            </BladeForEach>
        </Html>
    );
}
tsx
import { BladeForEach, BladeIf, blade } from '@mscode-pl/laravel-react-email';

export default function OrderEmail({
    total      = blade.number('total'),
    serviceFee = blade.number('serviceFee'),
}) {
    return (
        <Html>
            <BladeForEach items="items">
                <Text>$$item.name$$ — $$item.price$$ PLN</Text>
            </BladeForEach>

            <BladeIf condition="serviceFee > 0">
                <Text>Service fee: {serviceFee.toFixed(2)} PLN</Text>
            </BladeIf>

            <Text>Total: {total.toFixed(2)} PLN</Text>
        </Html>
    );
}