Back to Blog
Integration Guides

How to Integrate Twilio with Gravity Forms: Step-by-Step Guide

Add Twilio SMS notifications to Gravity Forms on WordPress to confirm submissions, alert admins, and trigger follow-up sequences from form data.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 22, 2026
7 min read
Twilio
Integration
Forms
How to Integrate Twilio with Gravity Forms: Step-by-Step Guide

Gravity Forms and Twilio integrate through the Gravity Forms gform_after_submission PHP hook and the Twilio PHP SDK to send SMS notifications when WordPress forms are submitted, enabling instant admin alerts for lead forms and confirmation messages to the submitter's phone number collected in the form. This integration is used by WordPress agencies and site owners who rely on Gravity Forms for contact, lead, and appointment booking forms and want to add SMS as an additional notification channel alongside Gravity Forms' built-in email notifications. The connection is implemented as a custom WordPress code snippet or plugin that hooks into Gravity Forms' submission workflow and calls the Twilio API with form entry data.

What You Need Before You Start

Install the Twilio PHP SDK in your WordPress environment by running composer require twilio/sdk from a custom plugin directory, creating a plugin file with a require_once pointing to the vendor/autoload.php Composer autoloader, and activating the plugin in the WordPress admin. Store your Twilio Account SID, Auth Token, and From Number as WordPress options by creating a settings page in your custom plugin using the WordPress Settings API with register_setting and add_settings_field, allowing the admin to enter credentials through the WordPress dashboard rather than hardcoding them. Identify the Gravity Forms field IDs for the phone and name fields in your form by opening the form in the Gravity Forms editor, clicking on each field, and reading the Field ID displayed in the field settings panel, as Gravity Forms stores entry data in arrays keyed by numeric field ID. From Twilio, provision an SMS-capable phone number and complete A2P 10DLC registration in the Twilio Console for US-bound SMS, and from Gravity Forms confirm you are on the Basic plan or higher which includes the PHP API and hook system required for this integration.

Step-by-Step Integration Guide

Hook into Gravity Forms submission events by adding the action in your WordPress plugin using add_action('gform_after_submission', 'twilio_send_sms_on_submission', 10, 2), where the callback receives the $entry array containing all form field values and the $form array containing form configuration. In the callback function, extract the submitter's phone by accessing $entry[$phoneFieldId] where $phoneFieldId is the integer field ID you identified for the phone field, and normalize the phone to E.164 by running preg_replace('/[^0-9+]/', '', $phone) and prepending the country code if needed. Initialize the Twilio client using new Twilio\Rest\Client(get_option('twilio_account_sid'), get_option('twilio_auth_token')) and dispatch the confirmation SMS by calling $client->messages->create($toPhone, ['from' => get_option('twilio_from_number'), 'body' => 'Thank you ' . $entry[$nameFieldId] . ', we received your submission and will contact you shortly.']). Send an admin alert by making a second Twilio create call with To set to your internal admin phone number and Body set to a notification string containing the submitter name, phone, email from $entry[$emailFieldId], and a summary of any key qualifying question fields, enabling the admin to respond immediately from their mobile phone.

Common Issues and How to Fix Them

Gravity Forms conditional logic can hide the phone field from certain form submitters who do not meet the display condition, causing $entry[$phoneFieldId] to be an empty string when accessed in the hook, which results in a Twilio API call with an empty To parameter that fails with error code 21210. Add a guard clause at the beginning of your hook callback that checks if ($entry[$phoneFieldId] === '' || is_null($entry[$phoneFieldId])) return; to exit the function gracefully when no phone is available, and log the entry ID to a database for review using Gravity Forms' built-in $entry['id'] identifier. The gform_after_submission hook fires synchronously during the WordPress page request that processes the form, and a slow Twilio API response can delay the confirmation page from loading for the user. Move the Twilio dispatch to an asynchronous process by using WordPress's wp_schedule_single_event function to queue the SMS send as a one-time WP-Cron job that fires immediately but runs in a separate request, keeping the form submission response fast. Gravity Forms multi-page forms fire the gform_after_submission hook only when the final page is submitted, but intermediate page saves using Gravity Forms Save and Continue fire a different hook, causing your SMS hook to miss forms that are partially completed and saved. If you want to trigger SMS on save-and-continue events as well, add a separate hook on gform_save_field_value and track whether an SMS has already been sent for that entry ID using Gravity Forms' update_entry_meta function to prevent duplicates.

How to Get More from This Integration

Build a Gravity Forms conditional SMS router by reading a dropdown or radio field from the entry using $entry[$serviceFieldId] and dispatching the admin alert to different team phone numbers based on the selected service, using a PHP switch statement to map field values to phone numbers stored in your WordPress options table, enabling automatic lead routing to the correct department by SMS. Add Gravity Forms entry update SMS by hooking into the gform_after_update_entry action which fires when an admin edits a Gravity Forms entry, extracting the changed field values using the $previous_values parameter, and dispatching a Twilio SMS to the submitter's stored phone notifying them of the update, such as a status change on a service request or approval of a submitted application. Create a Gravity Forms partial entry SMS by using the Gravity Forms Partial Entries add-on which saves form data as the user progresses, hooking into gform_partialentries_post_entry_created to detect incomplete form fills and dispatching a Twilio abandonment recovery SMS with a resume link after 60 minutes if the entry remains partial. Integrate Twilio with Gravity Forms Webhooks add-on as an alternative to PHP hooks by configuring the Webhooks add-on to POST form entry data to your middleware endpoint, handling the SMS dispatch in the middleware, and returning the SMS delivery status as a Gravity Forms entry note via the Gravity Forms REST API for full audit trail visibility within the Gravity Forms entry view.

Conclusion

Gravity Forms and Twilio together add instant SMS confirmation and admin alerting to every WordPress form submission, extending the already powerful Gravity Forms notification system with the immediacy of SMS. Get in touch with Telphi Consulting to build and deploy a custom Gravity Forms Twilio SMS plugin for your WordPress site.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.