axazara/mailify-laravel
最新稳定版本:v1.3
Composer 安装命令:
composer require axazara/mailify-laravel
包简介
This is the official Laravel client library for the Mailify ( Axa Zara Mail Service) API, which allows you to send emails.
README 文档
README
This is the official Laravel client library for the Mailify service API, which allows you to send emails.
Mailify::send('welcome_template')->to('yoyo.elimah@gmail.com')->now();
Installation
You can install the package via composer:
composer require axazara/mailify-laravel
php artisan mailify:install
You must publish the config file with:
php artisan mailify:install
This is the contents of the published config file:
return [
'api_key' => env('MAILIFY_API_KEY', 'default'),
'reply_to' => env('MAILIFY_REPLY_TO'),
'priority' => env('MAILIFY_PRIORITY', 0),
'queue' => env('MAILIFY_QUEUE', 'default'),
'env' => env('MAILIFY_ENV', 'live'),
'api_url' => env('MAILIFY_API_URL'),
];
Setup
To use Mailify, you muste set your API key in the config file or in the .env file.
MAILIFY_API_KEY=YOUR_API_KEY // Your Mailify API key
IMPORTANT
- Save your API key as an environment variable in your
.envfile. Do not hardcode it in your code.- You must not share your API key with anyone.
- You must not commit your API key to version control.
Templates
To use Mailify, you must define your templates in Mailify config file.
Mailify config file has a templates key which is an array of templates.
This array is for storing the templates.
The key is the name of the template and the value is the id of the template.
Example:
'templates' => [
'template_name' => 'template_id',
'welcome_template' => 'welcome_template_id',
'reset_password_template' => 'reset_password_template_id',
],
You can use the template name in the Mailify::send() method.
Example:
Mailify::send('template_name')->to('you@smile.com')->now();
IMPORTANT
- The template id must be a valid template id from your Mailify dashboard.
Usage
To send an Email, simply use the following syntax:
Mailify::send('template_name')->to('john@getmailify.com')->now();
send()is take the Mailify template nameto()is take the recipient email addressnow()if you want to send the email immediately
You can also pass another parameter though the below method :
Note: All parameters must be passed before the
now()orlater()method.
- Template parameters : (optional)
This is an array of parameters that will be passed to the template. The parameters will be available in the template as variables.
->with([
'name' => 'John Doe',
'order_id' => 1234,
])
- Reply to : (optional)
The reply to address is the address that will be used when the recipient replies to the email.
If not specified, the replyTo address will be the address specified in the Mailify dashboard.
You can also set default replyTo address in the config file or use MAILIFY_REPLY_TO environment variable in .env file.
->replyTo('team@exemple.com')
- Priority : (optional)
The priority of email.
Mailify supports 2 priority level : 0 (default) and 1 (high);
You can also set default priority in the config file or use the MAILIFY_PRIORITY environment variable in .env file.
Default priority is 0.
->priority(1)
Example Usage with full parameters
Mailify::send('template_name')
->to('john@example.com')
->with([
'name' => 'John Doe',
'order_id' => 1234,
])
->replyTo('help@company.com')
->priority(1)
->now();
Sending an email later
You may also choose to queue the email sending with later() or afterResponse() method.
later()method is send the email via queue Mailify use the Laravel queue system to send email thoughdefaultqueue. This is useful if you don't want to wait for the email to be sent before returning a response to the user or if you want to send the email in the background.Note:
- You must have a queue worker running in order to send the email. You can read more about queue workers in the Laravel documentation.
- If you want to use a custom queue, you need to set the MAILIFY_QUEUE environment variable to the name of the queue you wish to use. Be sure to have a queue worker running to process the queued messages, otherwise they will not be sent.
afterResponse()method is used to send email after the response is sent to the browser. This method do not require queue driver to be configured.Note: This method only work if your web server is using FastCGI or run with Laravel Octane (Swoole, RoadRunner).
Local Development
If you are using Mailify in a local development environment, you don't want to send real emails. Instead, you can use the Mailify with Mailtrap SMTP integration to view emails in your browser instead of sending them.
To avoid error in local development or testing environment you can set the MAILIFY_ENV environment variable to test in your .env file, this will prevent package to send email to Mailify API.
⚠️Be sure to set the MAILIFY_ENV environment variable to live when deploying to production.
MAILIFY_ENV=test
Error & Exceptions
If an error occurs while sending the email, an exception will be thrown. You can catch the exception and handle it accordingly.
try {
Mailify::send('template_name')->to('test@test.com')->now();
} catch (Exception $exception) {
// Handle the exception
}
Possible exceptions are :
Axazara\Mailify\Exceptions\ApiKeyIsMissingAxazara\Mailify\Exceptions\PriorityIsInvalidAxazara\Mailify\Exceptions\ReplyToIsInvalidAxazara\Mailify\Exceptions\SendingErrorAxazara\Mailify\Exceptions\ToIsInvalid
All error is logged in the laravel.log file, you can find the log file in the storage/logs directory.
Exceptions is thrown only if the APP_DEBUG environment variable is set to true.
Helpful links
- Read the Mailify documentation to learn more about Mailify.
- Read the Laravel documentation to learn more about Laravel.
- Read the Laravel Queue documentation to learn more about Laravel Queue.
- Read the Laravel Octane documentation to learn more about Laravel Octane.
- Read the Mailtrap documentation to learn more about Mailtrap.
Next features (TODO) :
- [ ] Add
->attach()method to attach file to email - [ ] Add
->bcc()method to send email to BCC - [ ] Add
->cc()method to send email to CC - [ ] Add
->from()method to set email sender - [ ] Add
->delay()method to delay mail sending to specified timestamp
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
If you've found a bug regarding security please mail hello@axazara.com instead of using the issue tracker..
Credits
License
The MIT License (MIT). Please see License File for more information.
axazara/mailify-laravel 适用场景与选型建议
axazara/mailify-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 931 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「AxaZara」 「mailify-laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 axazara/mailify-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 axazara/mailify-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 axazara/mailify-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This official Laravel Package for Laravel to interact with Moneroo API.
This is simple PHP Package for Laravel to interact with MailBluster API.
This is simple PHP Package to interact with MailZeet.
This is simple PHP Package for Laravel to interact with MailZeet API.
This is simple PHP Package to interact with Moneroo API.
Alfabank REST API integration
统计信息
- 总下载量: 931
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-20