wp_sms_send()
Send SMS messages programmatically using the wp_sms_send() function.
The wp_sms_send() function allows you to send SMS messages to any phone number or group of numbers programmatically. This is a powerful tool for developers who want to integrate SMS functionality into their WordPress themes or plugins.
Syntax
wp_sms_send( $to, $msg, $is_flash = false, $from = null, $mediaUrls = [] );
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
$to | array | Yes | — | The receiver number(s) |
$msg | string | Yes | — | The SMS text message |
$is_flash | boolean | No | false | Set to true to send as flash SMS |
$from | string | No | null | Custom sender ID |
$mediaUrls | array | No | [] | Media URLs for MMS messages |
Return Value
Returns true on success or WP_Error on failure.
Examples
Send SMS to Multiple Numbers
$to = array('+1111111111', '+1111111112');
$msg = "Your Message";
wp_sms_send($to, $msg);
Send Flash SMS
Flash SMS appears directly on the recipient’s screen without being stored in the inbox.
$to = array('+1111111111', '+1111111112');
$msg = "Your Message";
wp_sms_send($to, $msg, true);
Send MMS with Media
Include images or other media in your message.
$to = array('+1111111111', '+1111111112');
$msg = "Your Message";
$urls = ['https://example.com/image.jpg'];
wp_sms_send($to, $msg, false, null, $urls);
Send with Custom Sender ID
$to = array('+1111111111');
$msg = "Your Message";
wp_sms_send($to, $msg, false, 'MyCompany');
Error Handling
$to = array('+1111111111');
$msg = "Your Message";
$result = wp_sms_send($to, $msg);
if (is_wp_error($result)) {
error_log('SMS failed: ' . $result->get_error_message());
} else {
error_log('SMS sent successfully');
}
Notes
- Phone number format requirements depend on your gateway provider
- Flash SMS support depends on your gateway provider
- MMS support depends on your gateway provider
- Message length limits vary by provider (typically 160 characters for SMS)
Related
- wp_sms_add_subscriber - Action hook for new subscribers
- Send SMS Endpoint - REST API alternative
Last updated: December 23, 2024