# Send Contact Form 7 Submissions to a Webhook

> Posts each Contact Form 7 submission as JSON to a webhook URL, such as Zapier, Make, n8n or your CRM, so leads flow into your other tools automatically.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, webhook, integration
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-webhook/

## Code

```php
$wpide_cf7_webhook_forms = array(); // Form IDs to send; empty = all forms.

add_action( 'wpcf7_mail_sent', function ( $contact_form ) use ( $wpide_cf7_webhook_forms ) {
    $url = defined( 'WPIDE_CF7_WEBHOOK_URL' ) ? (string) WPIDE_CF7_WEBHOOK_URL : '';

    if ( ! in_array( wp_parse_url( $url, PHP_URL_SCHEME ), array( 'https', 'http' ), true ) ) {
        return;
    }
    if ( $wpide_cf7_webhook_forms && ! in_array( (int) $contact_form->id(), array_map( 'intval', $wpide_cf7_webhook_forms ), true ) ) {
        return;
    }

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

    $fields = array();
    foreach ( (array) $submission->get_posted_data() as $key => $value ) {
        if ( 0 !== strpos( $key, '_' ) ) {
            $fields[ $key ] = $value;
        }
    }

    $body = wp_json_encode( array(
        'form_id'    => (int) $contact_form->id(),
        'form_title' => $contact_form->title(),
        'fields'     => $fields,
        'page_url'   => (string) $submission->get_meta( 'url' ),
        'submitted'  => gmdate( 'c' ),
        'site'       => home_url(),
    ) );

    $headers = array( 'Content-Type' => 'application/json' );
    if ( defined( 'WPIDE_CF7_WEBHOOK_SECRET' ) && WPIDE_CF7_WEBHOOK_SECRET ) {
        $headers['X-Signature'] = hash_hmac( 'sha256', $body, WPIDE_CF7_WEBHOOK_SECRET );
    }

    wp_remote_post( $url, array( 'body' => $body, 'headers' => $headers, 'timeout' => 5, 'blocking' => false ) );
} );
```

## Notes

Define WPIDE_CF7_WEBHOOK_URL (and optionally WPIDE_CF7_WEBHOOK_SECRET for an X-Signature HMAC header) in wp-config.php; limit it to certain forms with the list at the top.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Contact Form 7 Submissions to a Webhook" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
