RestException is not a valid phone number on Twilio trial account

99 views Asked by At

I use twilio/sdk package, with the following code.

$sid = "AC3###############";
$token = "100################";

$from = $to = "+628********99";

$otp = rand(1111111, 9999999);

$client = new Twilio\Rest\Client($sid, $token);
$message = $client
  ->messages
  ->create($to, [
     'from' => $to, 
     'body' => 'OTP code : ' . $otp
  ])

This is the error that I got

Twilio\Exceptions\RestException [HTTP 400] Unable to create record: The 'To' number +628********99 is not a valid phone number.

What did I do wrong ? How can I use my trial account to send trial sms?

FYI the number I used is a verified number in Twilio and country origin is Indonesia +62.

1

There are 1 answers

5
IObert On

The line $token = '100################; is missing it's closing single quote. Could that be the reason?

PS: It's hard to build SMS OTP right because of fraud schemes like SMS Traffic Pumping Fraud. Twilio Verify has built-in protection against these risks.