friendsofhyperf/mail 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

friendsofhyperf/mail

最新稳定版本:v3.2.0-beta.1

Composer 安装命令:

composer require friendsofhyperf/mail

包简介

The Mailer for Hyperf.

README 文档

README

Latest Stable Version Total Downloads License

Email component of Hyperf

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

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

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<int, \FriendsOfHyperf\Mail\Mailables\Attachment>  */ public function attachments(): array { return []; } }

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

License

MIT

统计信息

  • 总下载量: 8.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固