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.2.1(3w ago)413.5k↓55.8%12MITPHPPHP ^8.1

Since Jun 5Pushed 2w 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 today

READMEChangelog (10)Dependencies (20)Versions (29)Used By (2)

Mail
====

[](#mail)

[中文说明](README_CN.md)

The mail component sends view, Markdown, HTML, and plain-text messages through Symfony Mailer transports.

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

[](#installation)

```
composer require friendsofhyperf/mail
php bin/hyperf.php vendor:publish friendsofhyperf/mail
```

Publishing the package creates `config/autoload/mail.php` and copies the mail view components to `storage/views/mail`. If your application does not already have the Hyperf view configuration, publish it separately:

```
php bin/hyperf.php vendor:publish hyperf/view
```

The package requires PHP 8.1 or later. Some features require optional packages:

- `hyperf/devtool` provides the `gen:mail` command.
- `aws/aws-sdk-php` is required for the `ses` and `ses-v2` transports.
- `symfony/http-client` is required for Symfony API mail transports.
- `symfony/mailgun-mailer` and `symfony/postmark-mailer` provide the corresponding transports.

Configuration
-------------

[](#configuration)

The published configuration defaults to the `log` mailer. Select a mailer with `MAIL_MAILER`, then configure it under `mail.mailers`. Supported transports are `smtp`, `sendmail`, `mail`, `mailgun`, `ses`, `ses-v2`, `postmark`, `log`, `array`, `failover`, and `roundrobin`. Custom transports can be registered with `Mail::extend()`.

```
// config/autoload/mail.php
use function Hyperf\Support\env;

return [
    'default' => env('MAIL_MAILER', 'log'),
    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'url' => env('MAIL_URL'),
            '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'),
            'scheme' => env('MAIL_SCHEME', 'smtp'),
        ],
        'log' => [
            'transport' => 'log',
            'group' => env('MAIL_LOG_GROUP', 'default'),
            'name' => env('MAIL_LOG_NAME', 'mail'),
        ],
    ],
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    'markdown' => [
        'theme' => env('MAIL_MARKDOWN_THEME', 'default'),
        'paths' => [
            BASE_PATH . '/storage/views/mail',
        ],
    ],
];
```

A mailer-specific `from`, `reply_to`, `to`, or `return_path` value overrides the corresponding global address. A global `to` address also removes the original To, Cc, and Bcc recipients before sending, which is useful in development.

Creating a Mailable
-------------------

[](#creating-a-mailable)

With `hyperf/devtool` installed, generate a view-based mailable or use `--markdown` to also create a Markdown template:

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

`Envelope` defines addresses, subject, tags, metadata, and Symfony message callbacks. `Content`accepts `view` (or its `html` alias), `text`, `markdown`, `htmlString`, and `with`. Public properties declared by your mailable are also exposed to the view.

```
namespace App\Mail;

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

class TestMail extends Mailable
{
    public function __construct(public readonly string $name)
    {
    }

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Test Mail');
    }

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

    public function attachments(): array
    {
        return [
            Attachment::fromPath(BASE_PATH . '/storage/report.pdf')
                ->as('report.pdf')
                ->withMime('application/pdf'),
        ];
    }
}
```

Attachments can also be created with `Attachment::fromData()`, `fromStorage()`, or `fromStorageDisk()`. A reusable attachable object may implement `FriendsOfHyperf\Mail\Contract\Attachable`.

Sending Mail
------------

[](#sending-mail)

`Mail::mailer()` selects a configured mailer; omitting its argument uses `mail.default`. The `to()`, `cc()`, and `bcc()` methods return a pending mail object whose `send()` method accepts a `FriendsOfHyperf\Mail\Contract\Mailable`. Sending returns a `SentMessage` or `null` when a `MessageSending` listener stops delivery.

```
use App\Mail\TestMail;
use FriendsOfHyperf\Mail\Facade\Mail;

Mail::mailer('smtp')
    ->to('user@example.com', 'Example User')
    ->cc('team@example.com')
    ->send(new TestMail('Hyperf'));
```

For messages that do not need a mailable class, the mailer also exposes `html()`, `raw()`, `plain()`, and `send()` with a view name or view array. The callback receives a `FriendsOfHyperf\Mail\Message`, which forwards unknown methods to the underlying Symfony `Email`.

```
use FriendsOfHyperf\Mail\Facade\Mail;
use FriendsOfHyperf\Mail\Message;

Mail::html('Hello', function (Message $message) {
    $message->to('user@example.com')->subject('Greeting');
});
```

###  Health Score

54

↑

FairBetter than 96% of packages

Maintenance96

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 75.8% 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 ~27 days

Recently: every ~47 days

Total

28

Last Release

24d 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 (25 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.2

### 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

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[illuminate/mail

The Illuminate Mail package.

5910.6M497](/packages/illuminate-mail)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[hyperf/database

A flexible database library.

192.9M321](/packages/hyperf-database)[hyperf/http-server

A HTTP Server for Hyperf.

103.0M371](/packages/hyperf-http-server)[hyperf/validation

hyperf validation

122.2M197](/packages/hyperf-validation)

PHPackages © 2026

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