gringlas/cakephp-mailjet-transport

为 cakePHP3 提供的 MailJet 邮件发送器传输器。

1.1.0 2020-06-17 06:24 UTC

This package is auto-updated.

Last update: 2024-09-17 15:41:30 UTC


README

此插件为 cakePHP 3 提供了一个简单的 MailJet 传输器。

使用方法

建议使用 cakePHP 的 Mailer 类。首先将 MailJetTransport 添加到您的 app.php

'EmailTransport' => [
        'default' => [
            'className' => 'gringlas\MailJetTransport\Mailer\MailJetTransport',
        ]
    ],

同时将您的凭据添加到 app.php

/**
     * MailJet credentials
     *
     * - key - MailJet Api key
     * - 'secret' - MailJet Api secret
     * - mailJetKeyInTemplateVars - if set to true templateVars from MailJet key will be taken and sent to MailJet,
     * otherwise send complete templateVars
     *
     */
    'MailJet' => [
        'key' => '1231sdasd',
        'secret' => 'asdasd123123',
        'mailJetKeyInTemplateVars' => false
    ],

要记录来自 MailJet API 的响应,请将记录器添加到 app.php

/**
* logging mailJet messages
*/
'mailJet' => [
    'className' => 'Cake\Log\Engine\FileLog',
    'path' => LOGS,
    'file' => 'mailJet',
    'url' => env('LOG_JETQUERIES_URL', null),
    'scopes' => ['mailJet']
],

在您的电子邮件配置文件中使用 TemplateID 作为 MailJet 交易模板。

如果您在 app.php 中使用 Email

'Email' => [

    'passwordreset' => [
        'TemplateID' => 1234,
        'subject' => 'Password Reset'
    ]
]

您也可以通过调用 setProfile() 在 Mailer 中直接添加 TemplateID。如果设置了 mailJetKeyInTemplateVars,请使用 setViewVars()MailJet 键中提供模板变量,否则所有变量将直接发送到 MailJet

public function passwordreset() {
    return $this
        ->setProfile([
            'TemplateID' => 1234
        ])
        ->setViewVars([
            'newPassword' => 'a192ja',
            'MailJet' => [
                'newPassword' => 'a192ja'
            ]
        ])
        ->setSubject('Password reset');
}

只有模板变量会被发送到 MailJet API。主题、发件人、... 都必须在 MailJet 模板中配置。因此,您可以轻松切换回 cakePHP 的默认 MailTransport