Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from pamjadz/twilio-WPSMS.php
Created June 12, 2025 10:13
Show Gist options
  • Save dexit/52e6f7cd0d0d7ae234ff6b06b1ab4fa0 to your computer and use it in GitHub Desktop.
Save dexit/52e6f7cd0d0d7ae234ff6b06b1ab4fa0 to your computer and use it in GitHub Desktop.
Twilio Wordpress Send SMS API
function twilioSendSMS($params = [], $endpoint = 'Messages.json'){
$sid = 'SID HERE';
$token = 'TOKEN HERE';
$request = wp_remote_get("https://api.twilio.com/2010-04-01/Accounts/{$sid}/{$endpoint}", [
'headers' => [
'Authorization' => 'Basic ' . base64_encode($sid . ':' . $token),
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
],
'body' => $params
]);
if( is_wp_error($request) ){
return wp_send_json(json_encode([
'status' => -1000,
'code' => $request->get_error_code(),
'message' => $request->get_error_message()
]));
} else {
return wp_send_json(wp_remote_retrieve_body($request));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment