Submit Contact Form 7 data to External API
-
add_action('wpcf7_before_send_mail','blog_cf7_api_sender' ); function blog_cf7_api_sender( $contact_form ) { $form_id = ( $contact_form )->id(); if ( $form_id == '02d6ca7') { $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $posted_data = $submission->get_posted_data(); $name = $posted_data['client-name']; $phone = $posted_data['client-phone']; $stream_code = [4yv1]; $token = [12345]; $url = 'https://coolapi.com'; $args = array( 'body' => json_encode(array( 'name' => $name, 'phone' => $phone, 'stream_code' => $stream_code, 'token' => $token, ) 'headers' => array( 'Authorization' => 'Bearer $token', 'Content-Type' => 'application/json', ) ); $response = wp_remote_post( $url, $args ); } } }
I have created a custom plugin within WordPress to POST contact form 7 data to an external API when a client submits their info, I followed a tutorial on YouTube step by step, but nothing is being posted to the API URL. I am not sure if it’s because the coding for contact form 7 is outdated now or if I am possibly using wp_remote_post incorrectly.
- The topic ‘Submit Contact Form 7 data to External API’ is closed to new replies.