mailersend/laravel-driver
Composer 安装命令:
composer require mailersend/laravel-driver
包简介
MailerSend Laravel Driver
README 文档
README
MailerSend Laravel Driver
Table of Contents
Installation
Requirements
- Laravel 10.0+
- PHP 8.2+
- Guzzle 7.0+
- An API Key from mailersend.com
For PHP 8.0/8.1 support, see 2.x branch
For Laravel 7.x - 8.x support see 1.x branch
Setup
You can install the package via composer:
composer require mailersend/laravel-driver
After that, you need to set MAILERSEND_API_KEY in your .env file:
MAILERSEND_API_KEY=
Add MailerSend as a Laravel Mailer in config/mail.php in mailers array:
'mailersend' => [ 'transport' => 'mailersend', ],
And set environment variable MAIL_MAILER in your .env file
MAIL_MAILER=mailersend
Also, double check that your FROM data is filled in .env:
MAIL_FROM_ADDRESS=app@yourdomain.com MAIL_FROM_NAME="App Name"
Usage
Old Syntax:
This is an example using the build mailable that you can use to send an email with.
app/Mail/TestEmail.php
namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Arr; use MailerSend\Helpers\Builder\Variable; use MailerSend\Helpers\Builder\Personalization; use MailerSend\LaravelDriver\MailerSendTrait; class TestEmail extends Mailable { use Queueable, SerializesModels, MailerSendTrait; public function build() { // Recipient for use with variables and/or personalization $to = Arr::get($this->to, '0.address'); return $this ->view('emails.test_html') ->text('emails.test_text') ->attachFromStorageDisk('public', 'example.png') // Additional options for MailerSend API features ->mailersend( template_id: null, tags: ['tag'], personalization: [ new Personalization($to, [ 'var' => 'variable', 'number' => 123, 'object' => [ 'key' => 'object-value' ], 'objectCollection' => [ [ 'name' => 'John' ], [ 'name' => 'Patrick' ] ], ]) ], precedenceBulkHeader: true, sendAt: new Carbon('2022-01-28 11:53:20'), ); } }
New Syntax:
This is an example using the new mailable syntax that you can use to send an email with.
app/Mail/TestEmail.php
<?php namespace App\Mail; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Attachment; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Arr; use MailerSend\Helpers\Builder\Personalization; use MailerSend\Helpers\Builder\Variable; use MailerSend\LaravelDriver\MailerSendTrait; class TestEmail extends Mailable { use Queueable, SerializesModels, MailerSendTrait; /** * Create a new message instance. */ public function __construct() { // } /** * Get the message envelope. */ public function envelope(): Envelope { return new Envelope( subject: 'Test Email', ); } /** * Get the message content definition. */ public function content(): Content { $to = Arr::get($this->to, '0.address'); // Additional options for MailerSend API features $this->mailersend( template_id: null, tags: ['tag'], personalization: [ new Personalization($to, [ 'var' => 'variable', 'number' => 123, 'object' => [ 'key' => 'object-value' ], 'objectCollection' => [ [ 'name' => 'John' ], [ 'name' => 'Patrick' ] ], ]) ], precedenceBulkHeader: true, sendAt: new Carbon('2022-01-28 11:53:20'), ); return new Content( view: 'emails.test_html', text: 'emails.test_text' ); } /** * Get the attachments for the message. * * @return array<int, \Illuminate\Mail\Mailables\Attachment> */ public function attachments(): array { return [ Attachment::fromStorageDisk('public', 'example.png') ]; } }
We provide a MailerSendTrait trait that adds a mailersend method to the mailable and allows you to use additional options that are available through our API.
After creating the mailable, you can send it using:
use App\Mail\TestEmail; use Illuminate\Support\Facades\Mail; Mail::to('recipient@domain.com') ->cc('cc@domain.com') ->bcc('bcc@domain.com') ->send(new TestEmail());
Please refer to Laravel Mail documenation and MailerSend API documentation for more information.
Support and Feedback
In case you find any bugs, submit an issue directly here in GitHub.
If you have any troubles using our driver, feel free to contact our support by email info@mailersend.com
Official API documentation is at https://developers.mailersend.com
License
mailersend/laravel-driver 适用场景与选型建议
mailersend/laravel-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 864.09k 次下载、GitHub Stars 达 90, 最近一次更新时间为 2020 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「transactional」 「mailersend」 「laravel-driver」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mailersend/laravel-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mailersend/laravel-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mailersend/laravel-driver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
MailerSend PHP SDK
An updated fork (psr-0 to psr-4) from the original library "Mandrill/Mandrill" (https://bitbucket.org/mailchimp/mandrill-api-php)
Sendernet transactional email php API client
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Official Laravel SDK for the ToSend email API
统计信息
- 总下载量: 864.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 90
- 点击次数: 37
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-14