-
Notifications
You must be signed in to change notification settings - Fork 11
/
example.php
56 lines (45 loc) · 1.79 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
*
* example code for using the phpList API Client
*
* For more information, visit https://github.com/michield/phplist-restapi-client
*
*
*/
include_once 'phpListRESTApiClient.php';
$apiURL = 'http://website.com/lists/admin/?page=call&pi=restapi';
$login = 'admin';
$password = 'helloworld';
$phpList = new phpListRESTApiClient($apiURL, $login, $password);
$phpList->tmpPath = '/var/tmp';
$subscriberEmail = '[email protected]';
if ($phpList->login()) {
$newListID = $phpList->listAdd('list '.rand(0, 100), 'This is a list made with the example code');
print 'Our new list has ID '.$newListID.PHP_EOL;
$subscriberID = $phpList->subscriberFindByEmail($subscriberEmail);
if (!empty($subscriberID)) {
$phpList->listSubscriberAdd($newListID, $subscriberID);
print "Subscriber $subscriberID has been added to the list".PHP_EOL;
} else {
$subscriberID = $phpList->subscribe($subscriberEmail, $newListID);
print "Subscriber has been subscribed to the list with ID $subscriberID".PHP_EOL;
}
$lists = $phpList->listsSubscriber($subscriberID);
print 'The subscriber is now member of '.PHP_EOL;
foreach ($lists as $list) {
print "\t".$list->id.' '.$list->name.PHP_EOL;
}
print 'Removing subscriber from the list'.PHP_EOL;
$lists = $phpList->listSubscriberDelete($newListID, $subscriberID);
print 'The subscriber is now member of '.PHP_EOL;
foreach ($lists as $list) {
print "\t".$list->id.' '.$list->name.PHP_EOL;
}
print 'And adding the subscriber to the list again'.PHP_EOL;
$lists = $phpList->listSubscriberAdd($newListID, $subscriberID);
print 'The subscriber is now member of '.PHP_EOL;
foreach ($lists as $list) {
print "\t".$list->id.' '.$list->name.PHP_EOL;
}
}