Automation

Automation: CF7 Integration Guide with Active Trail

A lightweight PHP solution that automatically sends CF7 form submissions directly to your Active Trail contact list — no manual export, no missed leads.

Automation: CF7 Integration Guide with Active Trail

A lightweight PHP solution that automatically sends CF7 form submissions directly to your Active Trail contact list — no manual export, no missed leads.

A common request we handle at CodeSpire is integrating Contact Form 7 with Active Trail, Israel's leading marketing automation platform. The goal is straightforward: when a visitor submits a CF7 form, their details should automatically be added to the right contact group in Active Trail.

This guide provides a lightweight PHP solution that handles the integration cleanly. It sends the subscriber's first name, last name, and email address to Active Trail via their API on every successful CF7 submission.

What You Will Need

  • A WordPress site with Contact Form 7 installed
  • An Active Trail account with API access enabled
  • Your Active Trail API key
  • The group ID of the mailing list you want to add subscribers to
  • The form ID of your CF7 form

How It Works

The integration hooks into the wpcf7_mail_sent action that CF7 fires after a form is successfully submitted. At that point, the function reads the form fields and sends the subscriber data to Active Trail via a cURL request to their REST API.

The Code

Place this function in your theme's functions.php file or in a custom plugin. Configure the three values marked below before activating.

function send_activetrails_subscription( $email, $fname, $lname ) {
    $api_key  = 'YOUR_API_KEY';   // Line 1: Your Active Trail API key
    $group_id = 'YOUR_GROUP_ID';  // Line 2: Contact group ID in Active Trail

    $data = json_encode([
        'status'     => 'Active',
        'email'      => $email,
        'first_name' => $fname,
        'last_name'  => $lname,
        'group_id'   => $group_id,
    ]);

    $ch = curl_init();
    curl_setopt_array( $ch, [
        CURLOPT_URL            => 'https://api.activetrail.biz/v1/contacts',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_HTTPHEADER     => [
            'Content-Type: application/json',
            'Authorization: Bearer ' . $api_key,
        ],
    ]);

    curl_exec( $ch );
    curl_close( $ch );
}

function active_trail_cf7_integration( $contact_form ) {
    $form_id = 'YOUR_CF7_FORM_ID'; // Your CF7 form ID (number)

    if ( (string) $contact_form->id() !== (string) $form_id ) {
        return;
    }

    $submission = WPCF7_Submission::get_instance();
    if ( ! $submission ) return;

    $data  = $submission->get_posted_data();
    $email = isset( $data['email'] )     ? sanitize_email( $data['email'] )           : '';
    $fname = isset( $data['firstname'] ) ? sanitize_text_field( $data['firstname'] )  : '';
    $lname = isset( $data['lastname'] )  ? sanitize_text_field( $data['lastname'] )   : '';

    if ( $email ) {
        send_activetrails_subscription( $email, $fname, $lname );
    }
}

add_action( 'wpcf7_mail_sent', 'active_trail_cf7_integration' );

Configuration: Three Things to Set

Before this works, you need to fill in three values:

  1. API Key — Go to your Active Trail account settings and generate an API key. Paste it in $api_key.
  2. Group ID — In Active Trail, navigate to your contact groups and find the numerical ID of the group you want new subscribers added to.
  3. Form ID — Open the CF7 form you want to connect. The form ID appears in the URL when editing it (e.g. post=123 — the number is your form ID).

The CF7 Form Structure

The field names in your form must match the variable names the function reads. Use this structure:

[text* firstname placeholder "First Name"]
[text* lastname  placeholder "Last Name"]
[email* email    placeholder "Email Address"]
[submit "Subscribe"]

Important: The field names firstname, lastname, and email must match exactly. If your form uses different field names, update the variable references in the PHP function accordingly.

Extending the Integration

This function is intentionally minimal. The Active Trail API supports many more contact fields. You can extend this to send additional data like phone number, city, or any custom field your form captures.

The same pattern works across multiple forms: duplicate the function, change the form ID, and point it to a different group — or add conditional logic to route different forms to different groups.

If you need help implementing this or want a more advanced setup, feel free to reach out to the CodeSpire team.