myqaa/laravel-sendinblue

SendinBlue 的 Laravel 邮件传输服务

v3.5.4 2023-04-17 11:38 UTC

README

SendinBlue 的 Laravel 邮件传输服务

Build Status

摘要

安装

composer require webup/laravel-sendinblue

兼容性

配置

config/mail.php

    'mailers' => [
        // ...
        'sendinblue' => [
            'transport' => 'sendinblue',
        ],
    ]

config/services.php

    'sendinblue' => [
        // api-key or partner-key
        'key_identifier' => env('SENDINBLUE_KEY_IDENTIFIER', 'api-key'),
        'key' => env('SENDINBLUE_KEY'),
    ],

.env

MAIL_MAILER=sendinblue
SENDINBLUE_KEY=your-access-key

# if you need to set the guzzle proxy config
# those are example values
HTTP_PROXY="tcp://:8125"
HTTPS_PROXY="tcp://:9124"
NO_PROXY=.mit.edu,foo.com

在带模板 ID 的可邮寄内容中使用

使用 sendinblue() 方法,您可以选择以下列出的额外字段。所有字段都是可选的

  • template_id (整数)
  • tags (数组)
  • params (数组)

如果您想使用模板中定义的主题,需要在 subject() 中传递 SendinBlueTransport::USE_TEMPLATE_SUBJECT 占位符。您也可以在这里覆盖主题文本。如果没有使用 subject() 方法,主题将来自类名。

可邮寄内容需要视图 - 在 view() 方法中传递空数组。

<?php

declare(strict_types=1);

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Webup\LaravelSendinBlue\SendinBlue; // <- you need this
use Webup\LaravelSendinBlue\SendinBlueTransport; // <- you need this

class MyMailable extends Mailable
{
    use Queueable;
    use SerializesModels;
    use SendinBlue; // <- you need this

    // ...

    public function build()
    {
        return $this
            ->view([])
            ->subject(SendinBlueTransport::USE_TEMPLATE_SUBJECT) // use template subject
            // ->subject('My own subject') // subject overridden
            ->sendinblue(
                [
                    'template_id' => 84,
                    'tags'        => ['offer'],
                    'params'      => [
                        'FIRSTNAME' => 'John',
                        'LINK'      => 'https://www.example.com',
                        'AMOUNT'    => '29',
                    ],
                ]
            );
    }
}

参数在 SendinBlue 模板中可通过以下方式访问

  • {{ params.FIRSTNAME }}
  • {{ params.LINK }}
  • {{ params.AMOUNT }}

您还可以在主题字段中使用参数替换,例如。
{{ params.FIRSTNAME }}, 忘记您的密码?!

注意:不要在变量名称中使用连字符 '-'。 {{ params.FIRST_NAME }} 将正常工作,但 {{ params.FIRST-NAME }} 将失败。来源: sendinblue/APIv3-php-library#151

关于其他功能

此库旨在提供与 SendInBlue 兼容的 Laravel 接口,以及支持模板 ID、标签和参数。

如果您需要类似特定 SendInBlue 测试版 SMTP 模板批处理等特性,您应直接使用官方的 SendInBlue PHP 库。