webguosai/hyperf-mailer

hyperf邮箱扩展包

dev-main 2025-04-11 09:48 UTC

This package is auto-updated.

Last update: 2025-04-11 09:48:02 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

简介

这个库只做smtp发送

运行环境

  • php >= 8.1
  • composer
  • hyperf >= 3.1

安装

composer require webguosai/hyperf-mailer -vvv

配置

发布配置

php bin/hyperf.php vendor:publish webguosai/hyperf-mailer

配置文件

use function Hyperf\Support\env;

return [
    'host'     => env('MAIL_HOST', 'smtp.exmail.qq.com'),
    'port'     => env('MAIL_PORT', 465),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
];

使用

发送邮件

try {
    mailer()->send(string $toMail, string $subject, string $body, array $attachments, bool $isHtml);
} catch (\PHPMailer\PHPMailer\Exception $e) {
    var_dump($e->getMessage());
}

Facade 发送

use Webguosai\HyperfSms\Facade;

Mailer::send(string $toMail, string $subject, string $body, array $attachments, bool $isHtml);

文档

https://github.com/PHPMailer/PHPMailer?tab=readme-ov-file#a-simple-example

License

MIT