Twilio SMS: E.164 Phone Number Formatting Required (Error 21211)

Hi @sandra @Ali

I wanted to share some results from testing the Twilio SMS gateway in Gibbon and get your thoughts on a possible improvement.

I set up a Twilio account, purchased a US SMS-enabled number, and configured Gibbon with the Twilio Account SID, Auth Token and sender number. After correcting the phone number format, I was able to successfully send SMS messages from both the Test SMS tool and the Messenger module to Ghanaian mobile numbers.

During testing I initially received the following Twilio error:

21211 – Invalid phone number format

Twilio requires recipient numbers in E.164 format:

+233530111222

However, the Test SMS page was passing:

233530111222

without the leading “+”.

To verify this, I temporarily modified:

modules/System Admin/thirdPartySettings_smsProcess.php

and prepended a “+” to the test recipient number before sending. After doing so, SMS messages were accepted by Twilio and delivered successfully.

The Messenger module also worked correctly once the number was formatted as E.164. Twilio delivery logs showed:

Message Created
Enqueued
Dequeued
Sent
Delivered

and the message was received on the handset.

My question is whether Gibbon should normalize SMS recipient numbers before sending them to the gateway, particularly for Twilio, which strictly requires E.164 formatting.

I noticed that src/Comms/SMS.php currently passes the recipient number directly to the SMS driver:

$message = [
‘to’ => $recipient,
‘from’ => $this->from,
‘content’ => $this->content,
];

Would it make sense to add a centralized normalization step there, or is there already another preferred location in the codebase where SMS phone numbers should be converted to E.164 format?

One other observation: Twilio worked reliably for delivery to Ghana, but the cost was approximately $0.3741 per SMS, which may be quite expensive for schools sending high volumes of notifications. For Ghana-based deployments, local gateways such as Hubtel or Nsano may be more cost-effective in the future.

Thanks for any guidance, and thanks for the excellent work on Gibbon.

Best regards