Mailin.php
17.3 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
/**
* Mailin REST client
*/
class Mailin
{
public $api_key;
public $base_url;
public $curl_opts = array();
public function __construct($base_url,$api_key)
{
if(!function_exists('curl_init'))
{
throw new Exception('Mailin requires CURL module');
}
$this->base_url = $base_url;
$this->api_key = $api_key;
}
/**
* Do CURL request with authorization
*/
private function do_request($resource,$method,$input)
{
$called_url = $this->base_url."/".$resource;
$ch = curl_init($called_url);
$auth_header = 'api-key:'.$this->api_key;
$content_header = "Content-Type:application/json";
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// Windows only over-ride
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth_header,$content_header));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
$data = curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch). '\n';
}
curl_close($ch);
return json_decode($data,true);
}
public function get($resource,$input)
{
return $this->do_request($resource,"GET",$input);
}
public function put($resource,$input)
{
return $this->do_request($resource,"PUT",$input);
}
public function post($resource,$input)
{
return $this->do_request($resource,"POST",$input);
}
public function delete($resource,$input)
{
return $this->do_request($resource,"DELETE",$input);
}
public function get_account()
{
return $this->get("account","");
}
public function get_smtp_details()
{
return $this->get("account/smtpdetail","");
}
public function create_child_account($email,$password,$company_org,$first_name,$last_name,$credits,$associate_ip)
{
return $this->post("account",json_encode(array("child_email"=>$email,"password"=>$password,"company_org"=>$company_org,"first_name"=>$first_name,"last_name"=>$last_name,"credits"=>$credits,"associate_ip"=>$associate_ip)));
}
public function update_child_account($child_authkey,$company_org,$first_name,$last_name,$password,$associate_ip,$disassociate_ip)
{
return $this->put("account",json_encode(array("auth_key"=>$child_authkey,"company_org"=>$company_org,"first_name"=>$first_name,"last_name"=>$last_name,"password"=>$password,"associate_ip"=>$associate_ip,"disassociate_ip"=>$disassociate_ip)));
}
public function delete_child_account($child_authkey)
{
return $this->delete("account/".$child_authkey,"");
}
public function get_reseller_child($child_authkey)
{
return $this->post("account/getchildv2",json_encode(array("auth_key"=>$child_authkey)));
}
public function add_remove_child_credits($child_authkey,$add_credits,$remove_credits)
{
return $this->post("account/addrmvcredit",json_encode(array("auth_key"=>$child_authkey,"add_credit"=>$add_credits,"rmv_credit"=>$remove_credits)));
}
public function send_sms($to,$from,$text,$web_url,$tag,$type)
{
return $this->post("sms",json_encode(array("text"=>$text,"tag"=>$tag,"web_url"=>$web_url,"from"=>$from,"to"=>$to,"type"=>$type)));
}
public function create_sms_campaign($camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
{
return $this->post("sms",json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
}
public function update_sms_campaign($id,$camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
{
return $this->put("sms/".$id,json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
}
public function send_bat_sms($campid,$mobilephone)
{
return $this->get("sms/".$campid,json_encode(array("to"=>$mobilephone)));
}
public function get_campaigns_v2($type,$status,$page,$page_limit)
{
return $this->get("campaign/detailsv2",json_encode(array("type"=>$type,"status"=>$status,"page"=>$page,"page_limit"=>$page_limit)));
}
public function get_campaign_v2($id)
{
return $this->get("campaign/".$id."/detailsv2","");
}
public function create_campaign($category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list,$attachmentUrl,$inline_image)
{
return $this->post("campaign",json_encode(array("category"=>$category,"from_name"=>$from_name,"name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"exclude_list"=>$exclude_list,"attachment_url"=>$attachmentUrl,"inline_image"=>$inline_image)));
}
public function delete_campaign($id)
{
return $this->delete("campaign/".$id,"");
}
public function update_campaign($id,$category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list,$attachmentUrl,$inline_image)
{
return $this->put("campaign/".$id,json_encode(array("category"=>$category,"from_name"=>$from_name,"name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"exclude_list"=>$exclude_list,"attachment_url"=>$attachmentUrl,"inline_image"=>$inline_image)));
}
public function campaign_report_email($id,$lang,$email_subject,$email_to,$email_content_type,$email_bcc,$email_cc,$email_body)
{
return $this->post("campaign/".$id."/report",json_encode(array("lang"=>$lang,"email_subject"=>$email_subject,"email_to"=>$email_to,"email_content_type"=>$email_content_type,"email_bcc"=>$email_bcc,"email_cc"=>$email_cc,"email_body"=>$email_body)));
}
public function campaign_recipients_export($id,$notify_url,$type)
{
return $this->post("campaign/".$id."/recipients",json_encode(array("notify_url"=>$notify_url,"type"=>$type)));
}
public function send_bat_email($campid,$email_to)
{
return $this->post("campaign/".$campid."/test",json_encode(array("emails"=>$email_to)));
}
public function create_trigger_campaign($category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list,$recurring,$attachmentUrl,$inline_image)
{
return $this->post("campaign",json_encode(array("category"=>$category,"from_name"=>$from_name,"trigger_name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"exclude_list"=>$exclude_list,"recurring"=>$recurring,"attachment_url"=>$attachmentUrl,"inline_image"=>$inline_image)));
}
public function update_trigger_campaign($id,$category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list,$recurring,$attachmentUrl,$inline_image)
{
return $this->put("campaign/".$id,json_encode(array("category"=>$category,"from_name"=>$from_name,"trigger_name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"exclude_list"=>$exclude_list,"recurring"=>$recurring,"attachment_url"=>$attachmentUrl,"inline_image"=>$inline_image)));
}
public function share_campaign($campaign_ids)
{
return $this->post("campaign/sharelinkv2",json_encode(array("camp_ids"=>$campaign_ids)));
}
public function update_campaign_status($id,$status)
{
return $this->put("campaign/".$id."/updatecampstatus",json_encode(array("status"=>$status)));
}
public function get_processes($page,$page_limit)
{
return $this->get("process",json_encode(array("page"=>$page,"page_limit"=>$page_limit)));
}
public function get_process($id)
{
return $this->get("process/".$id,"");
}
public function get_lists($page,$page_limit)
{
return $this->get("list",json_encode(array("page"=>$page,"page_limit"=>$page_limit)));
}
public function get_list($id)
{
return $this->get("list/".$id,"");
}
public function create_list($list_name,$list_parent)
{
return $this->post("list",json_encode(array("list_name"=>$list_name,"list_parent"=>$list_parent)));
}
public function delete_list($id)
{
return $this->delete("list/".$id,"");
}
public function update_list($id,$list_name,$list_parent)
{
return $this->put("list/".$id,json_encode(array("list_name"=>$list_name,"list_parent"=>$list_parent)));
}
public function display_list_users($listids,$page,$page_limit)
{
return $this->post("list/display",json_encode(array("listids"=>$listids, "page"=>$page, "page_limit"=>$page_limit)));
}
public function add_users_list($id,$users)
{
return $this->post("list/".$id."/users",json_encode(array("users"=>$users)));
}
public function delete_users_list($id,$users)
{
return $this->delete("list/".$id."/delusers",json_encode(array("users"=>$users)));
}
public function send_email($to,$subject,$from,$html,$text,$cc,$bcc,$replyto,$attachment,$headers)
{
return $this->post("email",json_encode(array("cc"=>$cc,"text"=>$text,"bcc"=>$bcc,"replyto"=>$replyto,"html"=>$html,"to"=>$to,"attachment"=>$attachment,"from"=>$from,"subject"=>$subject,"headers"=>$headers)));
}
public function get_webhooks($is_plat)
{
return $this->get("webhook",json_encode(array("is_plat"=>$is_plat)));
}
public function get_webhook($id)
{
return $this->get("webhook/".$id,"");
}
public function create_webhook($url,$description,$events,$is_plat)
{
return $this->post("webhook",json_encode(array("url"=>$url,"description"=>$description,"events"=>$events,"is_plat"=>$is_plat)));
}
public function delete_webhook($id)
{
return $this->delete("webhook/".$id,"");
}
public function update_webhook($id,$url,$description,$events)
{
return $this->put("webhook/".$id,json_encode(array("url"=>$url,"description"=>$description,"events"=>$events)));
}
public function get_statistics($aggregate,$tag,$days,$end_date,$start_date)
{
return $this->post("statistics",json_encode(array("aggregate"=>$aggregate,"tag"=>$tag,"days"=>$days,"end_date"=>$end_date,"start_date"=>$start_date)));
}
public function get_user($email)
{
return $this->get("user/".$email,"");
}
public function create_user($attributes,$blacklisted,$email,$listid)
{
return $this->post("user",json_encode(array("attributes"=>$attributes,"blacklisted"=>$blacklisted,"email"=>$email,"listid"=>$listid)));
}
public function delete_user($email)
{
return $this->delete("user/".$email,"");
}
public function update_user($email,$attributes,$blacklisted,$listid,$listid_unlink)
{
return $this->put("user/".$email,json_encode(array("attributes"=>$attributes,"blacklisted"=>$blacklisted,"listid"=>$listid,"listid_unlink"=>$listid_unlink)));
}
public function import_users($url,$listids,$notify_url,$name,$folder_id)
{
return $this->post("user/import",json_encode(array("url"=>$url,"listids"=>$listids,"notify_url"=>$notify_url,"name"=>$name,"list_parent"=>$folder_id)));
}
public function export_users($export_attrib,$filter,$notify_url)
{
return $this->post("user/export",json_encode(array("export_attrib"=>$export_attrib,"filter"=>$filter,"notify_url"=>$notify_url)));
}
public function create_update_user($email,$attributes,$blacklisted,$listid,$listid_unlink,$blacklisted_sms)
{
return $this->post("user/createdituser",json_encode(array("email"=>$email,"attributes"=>$attributes,"blacklisted"=>$blacklisted,"listid"=>$listid,"listid_unlink"=>$listid_unlink,"blacklisted_sms"=>$blacklisted_sms)));
}
public function get_attributes()
{
return $this->get("attribute","");
}
public function get_attribute($type)
{
return $this->get("attribute/".$type,"");
}
public function create_attribute($type,$data)
{
return $this->post("attribute",json_encode(array("type"=>$type,"data"=>$data)));
}
public function delete_attribute($type,$data)
{
return $this->post("attribute/".$type,json_encode(array("data"=>$data)));
}
public function get_report($limit,$start_date,$end_date,$offset,$date,$days,$email)
{
return $this->post("report",json_encode(array("limit"=>$limit,"start_date"=>$start_date,"end_date"=>$end_date,"offset"=>$offset,"date"=>$date,"days"=>$days,"email"=>$email)));
}
public function get_folders($page,$page_limit)
{
return $this->get("folder",json_encode(array("page"=>$page,"page_limit"=>$page_limit)));
}
public function get_folder($id)
{
return $this->get("folder/".$id,"");
}
public function create_folder($name)
{
return $this->post("folder",json_encode(array("name"=>$name)));
}
public function delete_folder($id)
{
return $this->delete("folder/".$id,"");
}
public function update_folder($id,$name)
{
return $this->put("folder/".$id,json_encode(array("name"=>$name)));
}
public function delete_bounces($start_date,$end_date,$email)
{
return $this->post("bounces",json_encode(array("start_date"=>$start_date,"end_date"=>$end_date,"email"=>$email)));
}
public function send_transactional_template($id,$to,$cc,$bcc,$attr,$attachmentUrl,$attachment)
{
return $this->put("template/".$id,json_encode(array("cc"=>$cc,"to"=>$to,"attr"=>$attr,"bcc"=>$bcc,"attachment_url"=>$attachmentUrl,"attachment"=>$attachment)));
}
public function create_template($from_name,$name,$bat_sent,$html_content,$html_url,$subject,$from_email,$reply_to,$to_field,$status,$attach)
{
return $this->post("template",json_encode(array("from_name"=>$from_name,"template_name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"status"=>$status,"attachment"=>$attach)));
}
public function update_template($id,$from_name,$name,$bat_sent,$html_content,$html_url,$subject,$from_email,$reply_to,$to_field,$status,$attach)
{
return $this->put("template/".$id,json_encode(array("from_name"=>$from_name,"template_name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,"status"=>$status,"attachment"=>$attach)));
}
public function get_senders($option)
{
return $this->get("advanced",json_encode(array("option"=>$option)));
}
public function create_sender($sender_name,$sender_email,$ip_domain)
{
return $this->post("advanced",json_encode(array("name"=>$sender_name,"email"=>$sender_email,"ip_domain"=>$ip_domain)));
}
public function update_sender($id,$sender_name,$sender_email,$ip_domain)
{
return $this->put("advanced/".$id,json_encode(array("name"=>$sender_name,"email"=>$sender_email,"ip_domain"=>$ip_domain)));
}
public function delete_sender($id)
{
return $this->delete("advanced/".$id,"");
}
}
?>