PHP-如何使用API为用户订阅MailerLite


PHP - How to subscribe user to MailerLite using API

在我的网站上,人们可以注册成为会员。现在我希望他们也能立即订阅我的MailerLite邮件列表。在API文档中,我找到了以下应该有效的PHP示例:

$ML_Subscribers = new MailerLite'Subscribers('xxxxxxxxxxxxxxxxxxxxxx');
            $subscriber = array(
                'email' => $e,
                'name' => $f,
            );
            $subscriber = $ML_Subscribers->setId('xxxxxxxxxxx')->setAutoresponders(false)->add($subscriber);

在他们的网站上提到的API网址如下:

https://app.mailerlite.com/api/v1/subscribers/{list_id}/

我不确定如何在脚本中实现此URL。。我有上面的PHP代码,应该向列表中添加一个订阅者,但我是否也应该以某种方式包含链接?我需要一些帮助才能使它发挥作用。提前感谢!

使用MailerLite SDK时,不需要发布到任何特定的终点。函数中有一些包装器,用于在向API发送数据时指定端点和方法请求类型。

以下提供的代码是所需的全部内容:

$ML_Subscribers = new MailerLite'Subscribers( API_KEY );
$subscriber = array(
    'email' => $e,
    'name' => $f,
);
$subscriber = $ML_Subscribers->setId( LIST_ID )->setAutoresponders(false)->add( $subscriber );

API_KEY替换为所提供的MailerLite API密钥,将LIST_ID替换为要将订阅者添加到的列表的ID。

否则,如果你没有使用他们的SDK,你需要对他们的端点进行POST:POSThttps://app.mailerlite.com/api/v1/subscribers/{list_id}/。您还需要构造要发送的包含your API Keyan Emailid of the subscriber list的适当数据对象。

您可以在MailerLite文档

中进一步了解这一点