// Twilio credentials
$account_sid = 'YOUR_TWILIO_ACCOUNT_SID';
$auth_token = 'YOUR_TWILIO_AUTH_TOKEN';
$twilio_number = 'YOUR_TWILIO_PHONE_NUMBER';
// The destination phone number and message content
$to_number = 'DESTINATION_PHONE_NUMBER';
$message_content = 'A post has been updated!';
// Twilio API URL
$url = 'https://api.twilio.com/2010-04-01/Accounts/' . $account_sid . '/Messages.json';
// Setup request to send json via POST
$data = array(
'From' => $twilio_number,
'To' => $to_number,
'Body' => $message_content
);
$post = http_build_query($data);
// Set up cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $account_sid . ':' . $auth_token);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// Send the request and get the response
$response = curl_exec($ch);
$error = curl_error($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL session handle
curl_close($ch);
// Check for errors and process the response
if ($error) {
error_log('Curl error: ' . $error);
} else {
// Process the response as needed
error_log('Twilio API response: ' . $response);
}