-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.php
72 lines (49 loc) · 1.58 KB
/
generator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// $argv = array(
// '$argv1' => 'number of emails',
// '$argv2' => 'email prefix',
// '$argv3' => 'email domain',
// '$argv4' => 'api key',
// '$argv5' => 'list id'
// );
// variables
$emails = array(); // email address array
$emailcount = $argv[1]; // number of emails
$apikey = $argv[4]; // MailChimp API key
$url = 'http://us8.api.mailchimp.com/3.0/lists/' . $argv[5] . '/members'; // API endpoint
// echo $url; // test endpoint value
// set values for $emails
for ($i = 0; $i < $emailcount; $i ++) {
$emails[$i] = $argv[2] . '+' . $i . '@' . $argv[3];
};
// var_dump($emails); // testing output
// output $emails values to terminal
foreach ($emails as $email) {
echo $email . "\r\n";
};
// subscribe each $email from $emails to list
foreach ($emails as $email) {
// $request is API request
$request = array(
'email_address' => $email, //
'status' => 'subscribed' //
);
// start API call
$ch = curl_init();
// define $options for API call
$options = array(
CURLOPT_USERPWD => "user:".$apikey, // authorization
CURLOPT_URL => $url, // endpoint
CURLOPT_USERAGENT => "representing_4.0/themgangstas", // user agent
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true, // call type (POST)
CURLOPT_POSTFIELDS => json_encode($request) // encoded JSON request
);
// set options for CURL request
curl_setopt_array($ch, $options);
// make API call, output HTTP response to $response
$response = json_decode(curl_exec($ch), true); // decoded JSON response
// test API response
var_dump($response);
}
?>