承接 juanparati/brevosuite 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

juanparati/brevosuite

Composer 安装命令:

composer require juanparati/brevosuite

包简介

Complete Brevo integration with Laravel

README 文档

README

What is it?

A complete Brevo suite for Laravel.

It provides the following features

  • Laravel native mail transport.
  • Transactional template transport.
  • Transactional SMS transport.
  • Native Brevo services (Contacts, Marketing, Accounts, Sales, etc).

Installation

For Laravel 13.x

composer require juanparati/brevosuite "^13.0"

For Laravel 12.x

  composer require juanparati/brevosuite "^12.0"

For Laravel 11.x

  composer require juanparati/brevosuite "^11.0"

For Laravel 10.x

  composer require juanparati/brevosuite "^10.0"

For older Laravel versions check Sendinblue v3 for Laravel.

  1. Add the following configuration snippet into the "config/services.php" file

      'brevo' => [        
          'key'   => '[your api key]'
      ],
    
  2. Change the mail driver to "brevo" into the "config/mail.php" file or the ".env" file (Remember that ".env" values will overwrite the config values). Example:

      'driver' => env('MAIL_MAILER', 'brevo'),
    
      'mailers' => [
          // ...
          'brevo' => [
              'transport' => 'brevo'
          ]
          // ...
      ];
    

Usage

Transactional mail transport

Just use the transactional e-mails using the Laravel Mail facade.

As soon that Brevo was configured as native mail transport you can use the following code in order to test it:

// Paste this code inside "artisan tinker" console.
Mail::raw('Test email', function ($mes) { 
    $mes->to('[youremail@example.tld]'); 
    $mes->subject('Test'); 
});

Transactional mail template transport

The transactional mail template transport allow to send templates as transactional e-mails using Brevo.

It's possible to register the mail template transport facade into the "config/app.php":

    'MailTemplate' => Juanparati\BrevoSuite\Facades\Template::class,

Now it's possible to send templates in the following way:

    MailTemplate::to('user@example.net');           // Recipient
    MailTemplate::cc('user2@example.net');          // CC
    MailTemplate::bcc('user3@example.net');         // BCC
    MailTemplate::replyTo('boss@example.net');      // ReplyTo
    MailTemplate::attribute('NAME', 'Mr User');     // Replace %NAME% placeholder into the template 
    MailTemplate::attach('file.txt');               // Attach file
    MailTemplate::attachURL('http://www.example.com/file.txt'); // Attach file from URL
    MailTemplate::send(100);                        // Send template ID 100 and return message ID in case of success

It's possible to reset the template message using the "reset" method:

    MailTemplate::to('user@example.net');           // Recipient
    MailTemplate::cc('user5@example.net');          // Second recipient
    MailTemplate::attribute('TYPE', 'Invoice');     // Replace %TYPE% placeholder
    MailTemplate::send(100);                        // Send template
    
    MailTemplate::to('user2@example.net');          // Another recipient
    MailTemplate::send(100);                        // Send template but attribute "type" and second recipient from previous e-mail is used
    
    MailTemplate::reset();                          // Reset message
    
    MailTemplate::to('user3@example.net');          
    MailTemplate::send(100);                        // Send template but previous attribute and second recipient is not used.

It's also possible enclose the mail message into a closure so the call to the "reset" method is not necessary:

    MailTemplate::send(100, function ($message) {
        $message->to('user2@example.net');
        
        // Note: Your template should contains the placeholder attributes surrounded by "%" symbol.
        // @see: https://help.brevo.com/hc/en-us/articles/360000268730-How-to-customize-your-transactional-emails
        $message->attributes(['placeholder1' => 'one', 'placeholder2' => 'two']);
        ...
    });        

Transactional SMS

The transactional SMS allow to send SMS using the Brevo SMS transport.

I's possible to register the SMS transport facade into the "config/app.php":

    'SMS' => Juanparati\BrevoSuite\Facades\Sms::class,

Usage examples:

    SMS::sender('TheBoss');         // Sender name (Spaces and symbols are not allowed)
    SMS::to('45123123123');         // Mobile number with internal code (ES)
    SMS::message('Come to work!');  // SMS message
    SMS::tag('lazydev');            // Tag (Optional)
    SMS::webUrl('http://example.com/endpoint'); // Notification webhook (Optional);
    SMS::send();

Like the transactional template transport, it is also possible reset the state using the "reset" method or just using a closure:

    SMS::send(function($sms) {
        $sms->to('45123123123');
        $sms->sender('Mr Foo');
        $sms->message('Hello Mr Bar');
        ...
    });

Laravel notifications

The following classes are provided as message builder for Laravel notifications:

  • TemplateMessage
  • SmsMessage

API Client

By default, this library uses the official GetBrevo PHP library.

In order to interact with the official library it's possible to inject the custom APIs in the following way:

    // Obtain APIClient
    $apliClient = app()->make(\Juanparati\BrevoSuite\Client::class);
    
    // Use the APIClient with the Brevo ContactsAPI
    $contactsApi = $apliClient->getApi('ContactsApi');
    
    // Retrieve the first 10 folders
    $folders = $contactsApi->getFolders(10, 0);  

Another example using Sendinblue models:

    $apiClient = app()->make(\Juanparati\BrevoSuite\Client::class);
    $contactsApi = $apiClient->getApi('ContactsApi');

    // Use CreateContact model
    $contact = $apiClient->getModel('CreateContact', ['email' => 'test@example.net', 'attributes' => ['TYPE' => 4, 'NOM' => 'test', 'PRENOM' => 'test'], 'listIds' => [22]]);

    try {
        $contactsApi->createContact($contact);
    }
    catch(\Exception $e){
        dd($e->getMessage());
    }

See the GetBrevo PHP library for more details.

Supported by

This project was made possible by Matchbanker.no.

juanparati/brevosuite 适用场景与选型建议

juanparati/brevosuite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.88k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2024 年 02 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mail」 「php」 「email」 「sms」 「laravel」 「sendinblue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 juanparati/brevosuite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 juanparati/brevosuite 我们能提供哪些服务?
定制开发 / 二次开发

基于 juanparati/brevosuite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-29