1

I want to dynamically sent the phone number (toNumber variable) CURLOPT_POSTFIELDS to field, How can I pass this $toNumber in CURLOPT_POSTFIELDS to:"" field? Advanced thanks .....

$mobileNumber = "002233245"; //its example phone number
$prefixCode = "880";
$toNumber = $prefixCode.$mobileNumber;


//now sent message
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sms.to/v1/sms/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>'{"body": "Dear customer, Your application success.","to": "Here_I_want_to_use_dynamically_phoneNumber_variable this $toNumber here","sender_id": "Bank","callback_url": "mydomain.com"}',
CURLOPT_HTTPHEADER => array(
      "Authorization: Bearer code",
      "Accept: application/json",
      "Content-Type: application/json"
 ),
));

1 Answers1

2

Build the post data in a normal array with the appropriate data...

$postData = [ "body" => "Dear customer, Your application success.",
    "to" => $toNumber,
    "sender_id" => "Bank",
    "callback_url" => "mydomain.com"
];

pass a json_encoded string to the post fields (update this line)...

CURLOPT_POSTFIELDS => json_encode($postData),
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55