1. Prepare Twilio
In Twilio, you need credentials and at least one valid sender. Twilio sends outbound SMS through the Messages resource, and each send request must include either a From value or a MessagingServiceSid. Twilio’s error docs also confirm that a missing sender causes the exact error you saw.
What to prepare:
- Account SID
- Auth Token
- One of:
- a Twilio SMS-capable phone number, or
- a Messaging Service SID, or
- in supported countries, an Alphanumeric Sender ID
2. Configure Perfex global SMS settings
In Perfex, go to:
Setup -> Settings -> SMS
Perfex’s own SMS provider guide says SMS providers are configured centrally there, and only one provider is active at a time.
Fill in:
- Twilio Account SID
- Twilio Auth Token
- sender config supported by your Perfex build
Your module should read from Perfex global settings, not duplicate SID/Auth Token in module settings. That avoids conflicts and keeps one source of truth. Perfex’s docs describe SMS provider setup as global configuration.
3. Choose your sender strategy
Use this priority:
- Messaging Service SID
- Alphanumeric Sender ID
- Twilio phone number
That order is practical because Messaging Services are Twilio’s recommended way to manage sending at scale, while Alphanumeric Sender IDs are good for branded one-way messaging in supported countries.
Important:
- Alphanumeric Sender IDs are generally one-way only.
- They are not supported everywhere and may require registration, including in the UK for protected Sender IDs.
4. Add module settings for SMS behavior
Keep only module-specific settings such as:
- Enable Twilio SMS
- Default SMS template
- Ready / Completed SMS template
- Force Alphanumeric Sender toggle
Do not duplicate:
- Account SID
- Auth Token
- From number
- Messaging Service SID
Those should come from Perfex global SMS settings.
5. Build the send method
Your FlexiShop send method should:
- load the repair job
- resolve the customer phone
- replace shortcodes in the recipient and message
- read global Twilio credentials
- read global sender settings
- send the message to Twilio’s Messages endpoint
Twilio’s API supports sending by POSTing to the Message resource.
A good internal flow is:
{
$account_sid = get_option('twilio_account_sid');
$auth_token = get_option('twilio_auth_token');
$messaging_service_sid = get_option('twilio_messaging_service_sid');
$alphanumeric_sender = get_option('twilio_alphanumeric_sender_id');
$from_number = get_option('twilio_from_number');
$payload = [
'To' => $resolved_to,
'Body' => $resolved_message,
];
if ($force_alphanumeric && $alphanumeric_sender !== '') {
$payload['From'] = $alphanumeric_sender;
} elseif ($messaging_service_sid !== '') {
$payload['MessagingServiceSid'] = $messaging_service_sid;
} elseif ($alphanumeric_sender !== '') {
$payload['From'] = $alphanumeric_sender;
} else {
$payload['From'] = $from_number;
}
// POST to:
// https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json
}
That matches Twilio’s documented requirement that outbound messages use either From or MessagingServiceSid.
6. Add shortcode support
Allow recipient and message shortcodes such as:
{customer_phone}{primary_phone}{client_phone}{contact_phone}{customer_name}{job_number}{status}{tracking_url}
When the user clicks Send SMS, resolve shortcodes before sending. This is module logic, not a Twilio requirement, but it makes the UI much easier to use.
7. Add a “Send SMS” button in the job card
On the repair details page:
- add a Send SMS button
- open a modal
- include:
- recipient field
- template dropdown
- editable message textarea
This lets staff preview and adjust the message before sending.
8. Add SMS templates
Create at least:
- Default SMS Template
- Ready / Completed SMS Template
For example:
and
9. Save a copy into Engineer Reports
After a successful send:
- create an engineer note
- set report type to
SMS - store:
- recipient
- final sent message
- timestamp
This gives you an audit trail inside the repair record.
10. Handle common Twilio errors
You should trap and surface Twilio API errors clearly. Important examples:
- missing sender
- invalid destination number
- unsupported sender type for country
- unregistered Alphanumeric Sender ID
Twilio’s error dictionary and specific 21603 page confirm sender-related failures.
11. Support Alphanumeric Sender ID correctly
If you add Force Alphanumeric Sender:
- only use it when a global Alphanumeric Sender ID exists
- otherwise stop and return a clear message
- do not silently fall back if the toggle is meant to force branding
Also remember:
- Alphanumeric Sender IDs are often country-specific
- they may need registration in certain regions, including the UK protected sender process.
12. Test with safe credentials first
Twilio provides test credentials and magic test numbers for validation flows. Their test credentials docs include example sender behavior for SMS testing.
Use that before live sending when possible.
13. Best practice: use Messaging Services if possible
If you expect growth, Messaging Services are usually cleaner than hardcoding one sender because they centralize sender pools, routing, and scaling behavior. Twilio’s Messaging Services docs recommend them for more complex messaging setups.
14. Minimum PHP/Twilio implementation choices
You can integrate Twilio in two ways:
- direct cURL to the REST API
- Twilio’s PHP helper library
Twilio provides an official PHP library for the REST API.
If you want lightweight integration inside a Perfex module, direct cURL is often simpler. If you want richer Twilio features later, the SDK is cleaner.
15. Recommended final setup for FlexiShop
Use this structure:
- Perfex global settings
- Account SID
- Auth Token
- From number / Messaging Service SID / Alphanumeric Sender
- FlexiShop settings
- enable SMS
- SMS templates
- force alphanumeric toggle
- Repair job page
- Send SMS button
- shortcode-aware modal
- save sent copy to Engineer Reports
That gives you:
- centralized credentials
- branded messaging support
- job-level audit history
- fewer config conflicts