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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.