PHPackages                             friendsofhyperf/mail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. friendsofhyperf/mail

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

friendsofhyperf/mail
====================

The Mailer for Hyperf.

v3.1.76(5mo ago)411.2k↓30.1%12MITPHPPHP ^8.1

Since Jun 5Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/friendsofhyperf/mail)[ Packagist](https://packagist.org/packages/friendsofhyperf/mail)[ Fund](https://hdj.me/sponsors/)[ GitHub Sponsors](https://github.com/huangdijia)[ RSS](/packages/friendsofhyperf-mail/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (25)Used By (2)

Mail
====

[](#mail)

[![Latest Stable Version](https://camo.githubusercontent.com/cc1ae57a7a815882d49507f83f414a3b87998f230ae99fe46abc5ff1e23d60eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667269656e64736f666879706572662f6d61696c)](https://packagist.org/packages/friendsofhyperf/mail)[![Total Downloads](https://camo.githubusercontent.com/74ded647725bf18381cdc62f2f35147799c360dd10d1228d49c21c63e4594ce9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64736f666879706572662f6d61696c)](https://packagist.org/packages/friendsofhyperf/mail)[![License](https://camo.githubusercontent.com/92940e31faf336055018d4b96fa0d4d4cb4d38cc4987e329f970cc475135f27d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f667269656e64736f666879706572662f6d61696c)](https://github.com/friendsofhyperf/mail)

Email component of Hyperf

Installation
------------

[](#installation)

- Request

```
composer require friendsofhyperf/mail
php bin/hyperf vendor:publish friendsofhyperf/mail
# Publish the view configuration file.
php bin/hyperf vendor:publish hyperf/view
```

Usage
-----

[](#usage)

```
// config/autoload/mail.php
/**
 * This file is part of friendsofhyperf/components.
 *
 * @link     https://github.com/friendsofhyperf/components
 * @document https://github.com/friendsofhyperf/components/blob/main/README.md
 * @contact  huangdijia@gmail.com
 */
use function Hyperf\Support\env;

return [
    /*
    |--------------------------------------------------------------------------
    | Default Mailer
    |--------------------------------------------------------------------------
    |
    | This option controls the default mailer that is used to send all email
    | messages unless another mailer is explicitly specified when sending
    | the message. All additional mailers can be configured within the
    | "mailers" array. Examples of each type of mailer are provided.
    |
    */

    'default' => env('MAIL_MAILER', 'log'),

    /*
    |--------------------------------------------------------------------------
    | Mailer Configurations
    |--------------------------------------------------------------------------
    |
    | Here you may configure all of the mailers used by your application plus
    | their respective settings. Several examples have been configured for
    | you and you are free to add your own as your application requires.
    |
    | Laravel supports a variety of mail "transport" drivers that can be used
    | when delivering an email. You may specify which one you're using for
    | your mailers below. You may also add additional mailers if needed.
    |
    | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
    |            "postmark", "resend", "log", "array",
    |            "failover", "roundrobin"
    |
    */

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'url' => env('MAIL_URL','smtp://xxx@xxx:xxx@xxx.com:465'),
            'host' => env('MAIL_HOST', '127.0.0.1'),
            'port' => env('MAIL_PORT', 2525),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
        ],

        'ses' => [
            'transport' => 'ses',
        ],

        'postmark' => [
            'transport' => 'postmark',
            // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'),
            // 'client' => [
            //     'timeout' => 5,
            // ],
        ],

        'resend' => [
            'transport' => 'resend',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
        ],

        'log' => [
            'transport' => 'log',
            'group' => env('MAIL_LOG_GROUP','default'),
            'name' => env('MAIL_LOG_NAME','mail'),
        ],

        'array' => [
            'transport' => 'array',
        ],

        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'smtp',
                'log',
            ],
        ],

        'roundrobin' => [
            'transport' => 'roundrobin',
            'mailers' => [
                'ses',
                'postmark',
            ],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all emails sent by your application to be sent from
    | the same address. Here you may specify a name and address that is
    | used globally for all emails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hyperf@hyperf.com'),
        'name' => env('MAIL_FROM_NAME', 'Hyperf'),
    ],

    /*
    |--------------------------------------------------------------------------
    | Markdown Mail Settings
    |--------------------------------------------------------------------------
    |
    | If you are using Markdown based email rendering, you may configure your
    | theme and component paths here, allowing you to customize the design
    | of the emails. Or, you may simply stick with the Laravel defaults!
    |
    */

    'markdown' => [
        'theme' => env('MAIL_MARKDOWN_THEME', 'default'),
        'paths' => [
            BASE_PATH . '/storage/views/mail',
        ],
    ],
];
```

### Build a Mail Class

[](#build-a-mail-class)

```
php bin/hyperf.php gen:mail TestMail
```

```
// app/Mail/TestMail.php

namespace App\Mail;

use FriendsOfHyperf\Mail\Mailable;
use FriendsOfHyperf\Mail\Mailable\Content;
use FriendsOfHyperf\Mail\Mailable\Envelope;

class TestMail extends Mailable
{

    /**
     * Create a new message instance.
     */
    public function __construct(
        private readonly string $name,
    ){}

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Test Mail',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            markdown: 'mail.test',
            with: [
                'name' => $this->name,
            ],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array
     */
    public function attachments(): array
    {
        return [];
    }
}
```

### Your Controller or Service

[](#your-controller-or-service)

```
// app/Controller/IndexController.php

use FriendsOfHyperf\Mail\Facade\Mail;

class IndexController extends AbstractController
{
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $mailer = Mail::mailer('smtp');
        $mailer->alwaysFrom('root@imoi.cn','Hyperf');

        $mailer->to('2771717608@qq.com')->send(new \App\Mail\TestMail($user));
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
```

Contact
-------

[](#contact)

- [Twitter](https://twitter.com/huangdijia)
- [Gmail](mailto:huangdijia@gmail.com)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance72

Regular maintenance activity

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~2 days

Total

24

Last Release

164d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8337659?v=4)[Deeka Wong](/maintainers/huangdijia)[@huangdijia](https://github.com/huangdijia)

---

Top Contributors

[![huangdijia](https://avatars.githubusercontent.com/u/8337659?v=4)](https://github.com/huangdijia "huangdijia (19 commits)")[![zds-s](https://avatars.githubusercontent.com/u/49744633?v=4)](https://github.com/zds-s "zds-s (6 commits)")[![andreluizmicro](https://avatars.githubusercontent.com/u/51085904?v=4)](https://github.com/andreluizmicro "andreluizmicro (1 commits)")[![guandeng](https://avatars.githubusercontent.com/u/7838221?v=4)](https://github.com/guandeng "guandeng (1 commits)")

---

Tags

mailerhyperfv3.1

### Embed Badge

![Health badge](/badges/friendsofhyperf-mail/health.svg)

```
[![Health](https://phpackages.com/badges/friendsofhyperf-mail/health.svg)](https://phpackages.com/packages/friendsofhyperf-mail)
```

###  Alternatives

[illuminate/mail

The Illuminate Mail package.

5910.1M391](/packages/illuminate-mail)[fedeisas/laravel-mail-css-inliner

Inline the CSS of your HTML emails using Laravel

5974.6M3](/packages/fedeisas-laravel-mail-css-inliner)[hyperf/validation

hyperf validation

122.1M166](/packages/hyperf-validation)[friendsofhyperf/sentry

The sentry component for Hyperf.

1864.6k](/packages/friendsofhyperf-sentry)[dotkernel/dot-mail

Dotkernel mail component based on symfony mailer

1140.0k5](/packages/dotkernel-dot-mail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
