Ramya Ramya - 1 year ago 96
PHP Question

Twilio Messages are not sending in PHP

I am using twilio api for sending messages.
Following is my script.

$AccountSid = "xxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxx";
$from = 'xxxxxxx';
$to = '+91xxxxxxxxxxxxx';

$uri = 'https://api.twilio.com/2010-04-01/Accounts/' . $AccountSid . '/SMS/Messages';
$auth = $AccountSid . ':' . $AuthToken;

$fields = '&To=' . urlencode( $to ) . '&From=' . urlencode( $from ) . '&Body=' . urlencode('This is my test message');

$res = curl_init();
curl_setopt( $res, CURLOPT_URL, $uri );
curl_setopt( $res, CURLOPT_POST, 3 );
curl_setopt( $res, CURLOPT_POSTFIELDS, $fields );
curl_setopt( $res, CURLOPT_USERPWD, $auth );
curl_setopt( $res, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec( $res );
return $result;

SMS are not coming to my mobile. Is twilio works for indian mobile numbers?

Answer Source

You script is correct. Yes, Twilio works for indian numbers.

Is your Twilio account is under trail mode. If it's in trail mode sms are not sent for non registered(Verified) mobile numbers. You have to register your mobile number in twilio service.

From twilio console verify your testing mobile number.

Use this url to https://www.twilio.com/console/phone-numbers/verified verify your mobile number.

After that verified mobile number will receive sms's.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download