Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################### FOR SENDING SMS ###########################
- $json_url = "http://api.ebulksms.com:8080/sendsms.json";
- $username = 'martafricanaltd@gmail.com';
- $apikey = '2bc9a4c7e451cb0529e1a31779e1a99c553f3017';
- $sendername = "MartAfrican";
- $recipients = "+96171238330";
- $flash = 0;
- $messagetext = "Hi, is enquiring about your product on martafricana";
- $gsm = array();
- $country_code = '961';
- $arr_recipient = explode(',', $recipients);
- foreach ($arr_recipient as $recipient) {
- $mobilenumber = trim($recipient);
- if (substr($mobilenumber, 0, 1) == '0'){
- $mobilenumber = $country_code . substr($mobilenumber, 1);
- }
- elseif (substr($mobilenumber, 0, 1) == '+'){
- $mobilenumber = substr($mobilenumber, 1);
- }
- $generated_id = uniqid('int_', false);
- $generated_id = substr($generated_id, 0, 30);
- $gsm['gsm'][] = array('msidn' => $mobilenumber, 'msgid' => $generated_id);
- }
- $message = array(
- 'sender' => $sendername,
- 'messagetext' => $messagetext,
- 'flash' => "{$flash}",
- );
- $request = array( 'SMS' => array(
- 'auth' => array(
- 'username' => $username,
- 'apikey' => $apikey
- ),
- 'message' => $message,
- 'recipients' => $gsm
- ));
- $json_data = json_encode($request);
- if ($json_data) {
- if (is_array($json_data)) {
- $json_data = http_build_query($json_data, '', '&');
- }
- $params = array('http' => array(
- 'method' => 'POST',
- 'content' => $json_data)
- );
- $headers = array('Content-Type: application/json');
- if ($headers !== null) {
- $params['http']['header'] = $headers;
- }
- $ctx = stream_context_create($params);
- $fp = fopen($json_url, 'rb', false, $ctx);
- echo "<script type='text/javascript'>alert('$params');</script>";
- echo "<script type='text/javascript'>alert('$ctx');</script>";
- echo "<script type='text/javascript'>alert('$fp');</script>";
- if (!$fp) {
- //return "Error: gateway is inaccessible";
- echo "<script type='text/javascript'>alert('gateway inaccessible');</script>";
- }
- else {
- try {
- $response = stream_get_contents($fp);
- $result = json_decode($response);
- echo "<script type='text/javascript'>alert('$response');</script>";
- }
- catch (Exception $e) {
- $response = $e->getMessage();
- echo "<script type='text/javascript'>alert('$response');</script>";
- }
- }
- }
- ############ END FOR SENDING SMS ###############
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement