emotality/laravel-everlytic

Laravel 扩展包,用于通过 Everlytic 发送事务性短信和邮件(邮件驱动)。

2.3.1 2024-05-02 10:10 UTC

This package is auto-updated.

Last update: 2024-09-02 10:50:55 UTC


README

License Latest Version Total Downloads

Laravel 扩展包,用于通过 Everlytic 发送事务性短信和邮件(邮件驱动)。

需求

  • PHP 8.0+
  • Laravel 9.0+

安装

  1. composer require emotality/laravel-everlytic
  2. php artisan vendor:publish --provider="Emotality\Everlytic\EverlyticServiceProvider"
  3. 将以下行添加到您的 .env 文件中
EVERLYTIC_URL="https://<everlytic_domain>.everlytic.net"
EVERLYTIC_USERNAME="<everlytic_username>"
EVERLYTIC_PASSWORD="<everlytic_password>"
  1. everlytic 块添加到 mailers 数组中,位于您的 config/mail.php 文件内
'mailers' => [
    ...
    'everlytic' => [
        'transport' => 'everlytic',
    ],
],
  1. 更新您的 .env 文件中的 MAIL_MAILER
MAIL_MAILER=everlytic

用法

发送电子邮件

就像您通常发送电子邮件一样!😄

向单个收件人发送短信

\Everlytic::sms('+27820000001', "1st Line\n2nd Line\n3rd Line");

响应将是一个 bool,如果成功则为 true,如果失败则为 false

向多个收件人发送短信

\Everlytic::smsMany(['+27820000001', '+27820000002'], "1st Line\n2nd Line\n3rd Line");

响应将是一个数组,键是收件人的电话号码,值是布尔值

array:2 [▼
  "+27820000001" => true
  "+27820000002" => false
]

通过通知发送电子邮件和/或短信

namespace App\Notifications;

use Emotality\Everlytic\EverlyticSms;
use Emotality\Everlytic\EverlyticSmsChannel;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    // Notification channels
    public function via($notifiable)
    {
        return ['mail', EverlyticSmsChannel::class];
    }
    
    // Send email
    public function toMail($notifiable)
    {
        return new \App\Mail\ExampleMail($notifiable);
    }
    
    // Send SMS
    public function toSms($notifiable) // Can also use toEverlytic($notifiable)
    {
        // Send SMS to a single recipient
        return (new EverlyticSms())
            ->to($notifiable->mobile) // Assuming $user->mobile
            ->message("1st Line\n2nd Line\n3rd Line");
            
        // or send SMS to multiple recipients
        return (new EverlyticSms())
            ->toMany(['+27820000001', '+27820000002'])
            ->message("1st Line\n2nd Line\n3rd Line");
    }
}

许可证

laravel-everlytic 根据 MIT 许可证发布。有关详细信息,请参阅 LICENSE