When i give a Pakistani phone number the code execute and send message successfully. But Whenever i give a Canadian or US phone number my WordPress causes error that says "The site is experiencing technical difficulties". I have no idea which type or what error is causing for this. Here is my code:
require_once dirname(__FILE__).'/vendor/autoload.php';
$sid = "***************************";
$token = "****************************";
$twilio = new Twilio\Rest\Client($sid, $token);
$phone_number = $twilio->lookups->v1->phoneNumbers($phone)->fetch(array("countryCode" => "US"));
$msg = "This is test Message.";
$message = $twilio->messages
->create($phone_number, // to +16048080668
array(
"body" => $message,
"from" => "*********"
)
);
print($message->sid);
Note: I am using Trial version of Twilio API and Both numbers Pakistani and Canadian are verified using Twilio.
I forget to update that I found the solution. I was missing the geo permission. One has to allow the geo permission of the country where they want to send SMS. The Geo permission option can be found in the Twilio dashboard settings page. I hope it will helpful for someone.