<?php
// Replace with your credentials and numbers
$apiKey = "bd2da0da";
$apiSecret = "VmHc0k4vyBqtqPDE";
$from = "17162770042";
$to = "17169039367";
$text = "Hello from Vonage!";
// Prepare the cURL request
$url = "https://rest.nexmo.com/sms/json";
$data = [
'api_key' => $apiKey,
'api_secret' => $apiSecret,
'to' => $to,
'from' => $from,
'text' => $text
];
// Initialize cURL
$ch = curl_init($url);
// Configure POST data and return transfer
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the request and get the response
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
} else {
// Print out the result from Vonage
echo "Response:\n" . $response;
}
// Close the cURL session
curl_close($ch);
?>