Last active
June 9, 2020 08:18
-
-
Save james-muriithi/a43d10f2df44fbfe857a8ff15e30fcb1 to your computer and use it in GitHub Desktop.
send sms to a number using php (with vaspro api)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function sendSms($phone, $message){ | |
| // required headers | |
| $stkheader = array('Content-Type:application/json','Cache-Control:no-cache'); | |
| // url to post the data | |
| $url = 'https://oyaa.co.ke/api/SendSms/'; | |
| # initiating curl | |
| $curl = curl_init(); | |
| // set curl url | |
| curl_setopt($curl, CURLOPT_URL, $url); | |
| // set cur headers | |
| curl_setopt($curl, CURLOPT_HTTPHEADER, $stkheader); //setting custom header | |
| // data to be posted to the url | |
| $curl_post_data = array( | |
| 'message' => $message, | |
| 'phone' => $phone, | |
| ); | |
| //json encode the data | |
| $data_string = json_encode($curl_post_data); | |
| // expect to return value from url | |
| curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
| // set method to POST | |
| curl_setopt($curl, CURLOPT_POST, true); | |
| // set the data to post | |
| curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); | |
| // print the response | |
| print_r(curl_exec($curl)); | |
| } | |
| sendSms('0746792699', 'hello there'); | |
| // currently i have insufficient airtime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment