php curl basic auth
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$host = 'http://google.com';
$message = 'Test message';
$phone = '998999999';
$username = 'username';
$password = 'password';
$post = [
"messages" => [
[
"recipient" => $phone,
"message-id" => "itrust" . strval(time()),
"sms" => [
"originator" => "3700",
"content" => [
"text" => $message
]
]
]
]
];
$payloadName = json_encode($post);
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadName);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);
echo '<pre>';
var_dump($return);
echo '</pre>';