onix-systems-php/hyperf-mailer

An extension to send email

v1.3.0 2024-02-05 09:06 UTC

This package is auto-updated.

Last update: 2024-04-05 09:33:36 UTC


README

Provides hyperf wrapper for the symfony/mailer package.

You can use features like High Availability and Load Balancing.

Includes the following classes:

  • Command:
    • GenMailCommand;
  • Contract:
    • HasLocalePreference;
    • HasMailAddress;
    • ShouldQueue;
  • Event:
    • MailMessageSending;
    • MailMessageSent.
  • Service:
    • EmailService.
  • Mail;
  • Mailable.

Install:

composer require onix-systems-php/hyperf-mailer

Publish config:

php bin/hyperf.php vendor:publish onix-systems-php/hyperf-mailer

Code Example:

<?php
declare(strict_types=1);

namespace App\Mail\Users;

use OnixSystemsPHP\HyperfMailer\Contract\ShouldQueue;
use OnixSystemsPHP\HyperfMailer\Mailable;

class TestEmail extends Mailable implements ShouldQueue
{
    public function __construct(private string $name)
    {
    }

    public function build(): void
    {
        $this
            ->subject('PHP Department welcome')
            ->textBody(sprintf('Hello, %s!', $this->name));
    }
}

...

$this->emailService->run(
    new User([
        'email' => $recipient[0],
        'first_name' => $recipient[1],
    ]),
    new TestEmail($recipient[1])
);

Based on https://github.com/hyperf-ext/mail