onix-systems-php/hyperf-mailer

用于发送电子邮件的扩展

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

This package is auto-updated.

Last update: 2024-09-05 10:23:27 UTC


README

symfony/mailer包提供hyperf包装器。

您可以使用诸如高可用性负载均衡等特性。

包括以下类

  • 命令
    • GenMailCommand;
  • 契约
    • HasLocalePreference;
    • HasMailAddress;
    • ShouldQueue;
  • 事件
    • MailMessageSending;
    • MailMessageSent.
  • 服务
    • EmailService.
  • Mail;
  • Mailable.

安装

composer require onix-systems-php/hyperf-mailer

发布配置

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

代码示例

<?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])
);

基于https://github.com/hyperf-ext/mail