0

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.

Win
  • 353
  • 1
  • 8

1 Answers1

0

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.

IObert
  • 2,118
  • 1
  • 10
  • 17
  • no that is not the case, i will adjust my question , thanks for notice it – Win Feb 01 '23 at 09:57
  • is it because i use non twilio number ? because the number is already verified before. – Win Feb 01 '23 at 09:59
  • Mhhh, could be. Can you try it with a Twilio number? – IObert Feb 01 '23 at 10:54
  • are there free twilio number available ? at least for testing to send to my own number – Win Feb 01 '23 at 10:55
  • No free ones but you could try to use a string as a sender to use an alphanumeric sender id if your country is supported without pre-registration https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID – IObert Feb 01 '23 at 14:38