Add Subscribers from Contact Form 7

Convert Contact Form 7 submissions into SMS subscribers.

Automatically add Contact Form 7 submissions to your SMS subscriber list.

Basic Integration

Add this code to your theme’s functions.php or a custom plugin:

function addNumberToSubscriberList($WPCF7_ContactForm)
{
    $name   = isset($_POST['your-name']) ? sanitize_text_field($_POST['your-name']) : "";
    $mobile = isset($_POST['your-mobile']) ? sanitize_text_field($_POST['your-mobile']) : "";

    if ($name && $mobile) {
        \WP_SMS\Newsletter::addSubscriber($name, $mobile, '1'); // Replace '1' with your group ID
    }
}
add_action('wpcf7_before_send_mail', 'addNumberToSubscriberList');

Configuration

  1. Replace your-name with your CF7 name field ID
  2. Replace your-mobile with your CF7 phone field ID
  3. Replace '1' with your subscriber group ID

With Group Selection

Allow users to choose which group to join:

Step 1: Add Dropdown to CF7

[select group "1|News" "2|Sport" "3|General"]

Step 2: Update Code

function addNumberToSubscriberList($WPCF7_ContactForm)
{
    $name   = isset($_POST['your-name']) ? sanitize_text_field($_POST['your-name']) : "";
    $mobile = isset($_POST['mobile-number']) ? sanitize_text_field($_POST['mobile-number']) : "";
    $group  = isset($_POST['group']) ? sanitize_text_field($_POST['group']) : "";

    if ($name && $mobile) {
        \WP_SMS\Newsletter::addSubscriber($name, $mobile, $group);
    }
}
add_action('wpcf7_before_send_mail', 'addNumberToSubscriberList');

Hook Reference

HookDescription
wpcf7_before_send_mailFires before CF7 sends confirmation email

Last updated: December 28, 2025