Enviar SMS con Twilio
function send_sms($number,$body)
{
$ID = '1234567890abcdef1234567890abcdef12';
$token = '1234567890abcdef1234567890abcdef';
$service = 'AB1234567890abcdef1234567890abcdef';
$url = 'https://api.twilio.com/2010-04-01/Accounts/' . $ID . '/Messages.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD,$ID . ':' . $token);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'To=' . rawurlencode('+' . $number) .
'&MessagingServiceSid=' . $service . // this is optionnel
//'&From=' . rawurlencode('+18885550000') . // this is required
'&Body=' . rawurlencode($body));
$resp = curl_exec($ch);
curl_close($ch);
return json_decode($resp,true);
}
/*
$ID and $token can be found under SMS / Dashboard / 'Show API Credentials' https://www.twilio.com/console/sms/dashboard
(Optional) $service can be found under SMS / Messaging Services / 'SID' https://www.twilio.com/console/sms/services
Comment out 'MessagingServiceSid=' and uncomment 'From=' to use direct sending from a single phone number
Finally, key information can be found buried in the kb here https://www.twilio.com/docs/sms/send-messages#send-a-message-with-an-image-url
*/
Hichem from Tunisia