· 5 years ago · Jul 20, 2020, 08:10 PM
1<?php
2
3$curl = curl_init();
4
5curl_setopt_array($curl, array(
6 CURLOPT_URL => "https://api.sms.to/sms/send",
7 CURLOPT_RETURNTRANSFER => true,
8 CURLOPT_ENCODING => "",
9 CURLOPT_MAXREDIRS => 10,
10 CURLOPT_TIMEOUT => 0,
11 CURLOPT_FOLLOWLOCATION => true,
12 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13 CURLOPT_CUSTOMREQUEST => "POST",
14 CURLOPT_POSTFIELDS =>"{\n \"message\": \"This is test\",\n \"to\": \"+9779856034616\",\n \"sender_id\": \"SMSto\",\n \"callback_url\": \"https://example.com/callback/handler\"\n}",
15 CURLOPT_HTTPHEADER => array(
16 "Content-Type: application/json",
17 "Accept: application/json",
18 "Authorization: Bearer <YOUR_API_KEY_OR_ACCESS_TOKEN>"
19 ),
20));
21
22$response = curl_exec($curl);
23
24curl_close($curl);
25echo $response;
26
27OR
28// Using API Key via Query Param
29
30$curl = curl_init();
31
32curl_setopt_array($curl, array(
33 CURLOPT_URL => "https://api.sms.to/sms/send?api_key={api_key}&to=9779856034616&message=test&sender_id=smsto",
34 CURLOPT_RETURNTRANSFER => true,
35 CURLOPT_ENCODING => "",
36 CURLOPT_MAXREDIRS => 10,
37 CURLOPT_TIMEOUT => 0,
38 CURLOPT_FOLLOWLOCATION => true,
39 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
40 CURLOPT_CUSTOMREQUEST => "GET",
41));
42
43$response = curl_exec($curl);
44
45curl_close($curl);
46echo $response;
47
48 RESPONSE:
49
50{
51 "message": "Message is queued for sending! Please check report for update",
52 "success": true,
53 "message_Id": "e7745289-7236-497f-acf2-f9cfd6a86f16"
54}