Skip to content

Instantly share code, notes, and snippets.

@pamjadz
Created October 2, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamjadz/8f229a3da8ab052425eda91a314dbe31 to your computer and use it in GitHub Desktop.
Save pamjadz/8f229a3da8ab052425eda91a314dbe31 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