xlabs/ynotmailbundle

YNotMail 组件

安装: 196

依赖: 1

建议者: 0

安全: 0

类型:symfony-bundle

1.0.5 2022-07-07 11:51 UTC

This package is auto-updated.

Last update: 2024-09-07 16:32:32 UTC


README

YNot Mail API 包装器。

安装

通过 composer 安装

php -d memory_limit=-1 composer.phar require xlabs/ynotmailbundle

在你的 AppKernel 中

public function registerbundles()
{
    return [
    	...
    	...
    	new XLabs\YNotMailBundle\XLabsYNotMailBundle(),
    ];
}

将以下命令添加到 crontab 以更新 YNotMail 用户列表

55 23 * * * /usr/bin/php <symfony_project_folder>/bin/console cron:daily:ynot:update_lists

配置示例

以下显示默认值

# app/config/config.yml

x_labs_ynot_mail:
    api:
        url: 'https://www.ynotmail.com/clients/remote-api.php'
        username: ############
        token: ############
    lists:
        expired_members: {id: xxxx, query: "SELECT * FROM..."}
        alias_2: {id: <list_id_2>, query: "SELECT * FROM..."}
        ...
        alias_N: {id: <list_id_N>, query: "SELECT * FROM..."}
        ...

使用方法

通过以下方式从控制器实例化服务:

$api = $this->get('xlabs_ynot_mail');

然后使用 "_call" 方法执行请求,该方法使用 3 个参数:方法、参数和多个标志。如果 "multiple" 为 true,它将期望一个参数数组。如果参数已经是数组,它将期望一个数组数组。

方法

创建列表

$api->_call('createList', array(
    'name' => 'test',
    'ownerEmail' => 'test_owner@mm.com',
    'ownerName' => 'test',
    'replyEmail' => 'test_reply@mm.com',
    'companyName' => 'test',
    'companyAddress' => 'test',
    'companyPhones' => 'test'
));

获取列表

$api->_call('getLists');

删除列表

$api->_call('deleteList', $list_id);

向列表添加订阅者

$api->_call('addSubscriberToList', array(
    'listId' => $list_id,
    'subscriber' => array(
        'email' => 'my@email.com',
        'format' => 'html'
    )
));

向列表添加多个订阅者的多次调用如下所示

$api->_call('addSubscriberToList', array(
    array(
        'listId' => $list_id,
        'subscriber' => array(
            'email' => 'first@email.com',
            'format' => 'html'
        )
    ),
    array(
        'listId' => $list_id,
        'subscriber' => array(
            'email' => 'second@email.com',
            'format' => 'html'
        )
    )
), $multiple = true);

从列表中删除订阅者

$api->_call('deleteSubscriber', array(
    'listId' => $list_id,
    'subscriberId' => 'my@email.com'
));