PHP code example of drese / laravel-maileroo

1. Go to this page and download the library: Download drese/laravel-maileroo 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/ */

    

drese / laravel-maileroo example snippets


'mailers' => [
    'maileroo' => [
        'transport' => 'maileroo',
    ],
    // ... other mailers
],

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

Mail::to('[email protected]')->send(new WelcomeEmail($user));

$user->notify(new InvoicePaid($invoice));

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Queue\SerializesModels;

class WelcomeEmail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public $user
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            from: new Address('[email protected]', 'Welcome Team'),
            subject: 'Welcome to Our Platform!',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.welcome',
        );
    }

    public function attachments(): array
    {
        return [];
    }
}

use Drese\LaravelMaileroo\Facades\Maileroo;

Maileroo::sendEmail([
    'from' => '[email protected]',
    'to' => '[email protected]',
    'subject' => 'Hello',
    'html' => '<h1>Hello World!</h1>',
    'plain' => 'Hello World!',
]);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Drese\LaravelMaileroo\Facades\Maileroo;

class ContactController extends Controller
{
    public function submit(Request $request)
    {
        $validated = $request->validate([
            'name' => 'New Contact: ' . $validated['subject']
        );

        return back()->with('success', "Message sent! Reference: {$referenceId}");
    }
}

use Drese\LaravelMaileroo\MailerooFormService;

class ContactController extends Controller
{
    public function submit(Request $request, MailerooFormService $maileroo)
    {
        $validated = $request->validate([
            'name' => 'ission'
        );

        return back()->with('success', "Message sent! Reference: {$referenceId}");
    }
}

namespace App\Services;

use Maileroo\MailerooClient;
use Maileroo\EmailAddress;
use Maileroo\Attachment;

class EmailService
{
    public function __construct(
        protected MailerooClient $client
    ) {}

    public function sendInvoice($invoice)
    {
        return $this->client->sendBasicEmail([
            'from' => new EmailAddress('[email protected]', 'Billing Team'),
            'to' => new EmailAddress($invoice->customer->email, $invoice->customer->name),
            'subject' => 'Invoice #' . $invoice->number,
            'html' => view('emails.invoice', compact('invoice'))->render(),
            'attachments' => [
                Attachment::fromFile($invoice->pdf_path, 'application/pdf')
            ],
            'tags' => [
                'type' => 'invoice',
                'customer_id' => $invoice->customer_id,
            ],
            'reference_id' => 'invoice-' . $invoice->id,
        ]);
    }
}

public function scheduleEmail()
{
    return $this->client->sendBasicEmail([
        'from' => new EmailAddress('[email protected]'),
        'to' => new EmailAddress('[email protected]'),
        'subject' => 'Scheduled Email',
        'html' => '<p>This will be sent later</p>',
        'scheduled_at' => date('c', strtotime('+1 day')),
    ]);
}

public function sendBulk()
{
    return $this->client->sendBulkEmails([
        'subject' => 'Newsletter',
        'html' => '<h1>Hello {{name}}!</h1>',
        'messages' => [
            [
                'from' => new EmailAddress('[email protected]'),
                'to' => new EmailAddress('[email protected]'),
                'template_data' => ['name' => 'John'],
            ],
            [
                'from' => new EmailAddress('[email protected]'),
                'to' => new EmailAddress('[email protected]'),
                'template_data' => ['name' => 'Jane'],
            ],
        ],
    ]);
}
bash
php artisan vendor:publish --tag=maileroo-config