-
-
Save dexit/52e6f7cd0d0d7ae234ff6b06b1ab4fa0 to your computer and use it in GitHub Desktop.
Twilio Wordpress Send SMS API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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