【问题标题】:How to add 1 subscriber to multiple MailWizz (with different APIs and domains)?如何将 1 个订阅者添加到多个 MailWizz(具有不同的 API 和域)?
【发布时间】:2020-08-04 22:19:09
【问题描述】:

我买了 MailWizz,非常棒。而且 API 非常易于使用:

https://github.com/twisted1919/mailwizz-php-sdk

https://api-docs.mailwizz.com/#subscribers-create

我需要将此单个订阅者添加到 2 个不同域中的 2 个不同 API。但我不知道该怎么做,因为我只需要使用 1 个 setup.php 文件。

我只是用名称和电子邮件字段创建了我的 HTML 时事通讯表单,并使用以下代码定向到 save.php 文件:

<?php
// require the setup which has registered the autoloader
require_once dirname(__FILE__) . '/setup.php';

// CREATE THE ENDPOINT
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();

if (!empty($_POST)) {
    // CREATE / UPDATE EXISTING SUBSCRIBER
    $response = $endpoint->createUpdate('id-my-list', array(
        'EMAIL'    => isset($_POST['EMAIL']) ? $_POST['EMAIL'] : null,
        'FNAME'    => isset($_POST['FNAME']) ? $_POST['FNAME'] : null
    ));
}
?>

setup.php

<?php// require the autoloader class if you haven't used composer to install the package
require_once dirname(__FILE__) . '/MailWizzApi/Autoloader.php';

// register the autoloader if you haven't used composer to install the package
MailWizzApi_Autoloader::register();

// configuration object
$config = new MailWizzApi_Config(array(
    'apiUrl'        => 'https://site1.com/mailwizz/api/',
    'publicKey'     => '0000000',
    'privateKey'    => '11111111',

    // components
    'components' => array(
        'cache' => array(
            'class'     => 'MailWizzApi_Cache_File',
            'filesPath' => dirname(__FILE__) . '/MailWizzApi/Cache/data/cache', // make sure it is writable by webserver
        )
    ),
));

// now inject the configuration and we are ready to make api calls
MailWizzApi_Base::setConfig($config);

// start UTC
date_default_timezone_set('UTC');
?>

我有 2 个 API

'apiUrl' => 'https://site1.com/mailwizz/api/',
'publicKey' => '0000000',
'privateKey' => '11111111',

and
'apiUrl' => 'https://other-site2.com/mailwizz-new/api/',
'publicKey' => '22222222',
'privateKey' => '333333333',

谢谢。

【问题讨论】:

  • 对于 site1 工作正常。但我也不知道如何将它保存在 site2 上,因为它是不同的 api,setup.php 中的不同域和 save.php 文件中的不同“id-my-list”(id- my-list1 和 id-my-list2)。

标签: php mysql api email web-development-server


【解决方案1】:

这可能会对您有所帮助:

    <?php

require_once dirname(__FILE__) . '/MailWizzApi/Autoloader.php';

// register the autoloader if you haven't used composer to install the package
MailWizzApi_Autoloader::register();

date_default_timezone_set('UTC');

$sites = [
    [
        'list_uid' => 'xxx',
        'config' => [
            'apiUrl'        => 'https://site1.com/mailwizz/api/',
            'publicKey'     => '0000000',
            'privateKey'    => '11111111',
        ]
    ],
    [
        'list_uid' => 'xxx',
        'config' => [
            'apiUrl'        => 'https://other-site2.com/mailwizz-new/api/',
            'publicKey'     => '22222222',
            'privateKey'    => '333333333',
        ]
    ]
];

foreach ($sites as $site) {

    $config = new MailWizzApi_Config($site['config']);

    MailWizzApi_Base::setConfig($config);

    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();

    $response = $endpoint->createUpdate($site['list_uid'], array(
        'EMAIL'    => isset($_POST['EMAIL']) ? $_POST['EMAIL'] : '',
        'FNAME'    => isset($_POST['FNAME']) ? $_POST['FNAME'] : ''
    ));

}

虽然示例使用setup.php 文件,但这并不意味着您也必须使用它。这只是一个例子。

【讨论】:

  • 谢谢!完美,你是对的,很好的解决方案。唯一的问题是我有 2 个不同的列表 ID(id-my-list1 和 id-my-list2),我可以把这个变量放在数组 $sites 中吗? $response = $endpoint->createUpdate('id-my-list'
  • 谢谢扭曲!现在我看到是你,支持我的用户。有了这个新的解决方案,我将在 CodeCanyon 购买更多版本的 MailWizz 来安装在我的客户身上!非常感谢并祝贺优秀的系统
猜你喜欢
  • 1970-01-01
  • 2018-05-15
  • 2016-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 2019-09-15
  • 1970-01-01
相关资源
最近更新 更多