Skip to content

How to replace this res Api with 46elks? #16

@Hussein-ipc

Description

@Hussein-ipc
function sendSms($mobile, $otp) {
     
    $otp_prefix = ':';
 
    //Your message to send, Add URL encoding here.
    $message = urlencode("Hello. Your OPT is '$otp_prefix $otp'");
 
    $response_type = 'json';
 
    //Define route 
    $route = "4";
     
    //Prepare you post parameters
    $postData = array(
        'authkey' => xxxxx_AUTH_KEY,
        'mobiles' => $mobile,
        'message' => $message,
        'sender' => XXXX_SENDER_ID,
        'route' => $route,
        'response' => $response_type
    );
 
//API URL
    $url = "https://control.XXXXXX.com/sendhttp.php";
 
// init the resource
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $postData
            //,CURLOPT_FOLLOWLOCATION => true
    ));
 
 
    //Ignore SSL certificate verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
 
    //get response
    $output = curl_exec($ch);
 
    //Print error if any
    if (curl_errno($ch)) {
        echo 'error:' . curl_error($ch);
    }
 
    curl_close($ch);
}
?>
function sendSMS ($sms) {

  // Set your 46elks API username and API password here
  // You can find them at https://dashboard.46elks.com/
  $username = 'u2c11ef65b429a8e16ccb1f960d02c734';
  $password = 'C0ACCEEC0FAFE879189DD5D57F6EC348';

  $context = stream_context_create(array(
    'http' => array(
      'method' => 'POST',
      'header'  => "Authorization: Basic ".
                   base64_encode($username.':'.$password). "\r\n".
                   "Content-type: application/x-www-form-urlencoded\r\n",
      'content' => http_build_query($sms),
      'timeout' => 10
  )));

  return false !== file_get_contents(
    'https://api.46elks.com/a1/SMS', false, $context );
}


$sms = array(
  'from' => 'DummyFrom',   /* Can be up to 11 alphanumeric characters */
  'to' => '+46400000000',  /* The mobile number you want to send to */
  'message' => 'Hello hello!'
);
sendSMS ($sms);

?>
  1. Can somebody help me two variable $mobile and $otp in fun( ) and $sms in func 46elks.

  2. How can I declare $mobile and $otp in $sms to pass 46elks ?

  3. I am new in php?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions