• Resolved arbremojo

    (@arbremojo)


    Hi,

    I wrote the following function in my functions.php:

    add_action( 'wpcf7_before_send_mail',
        function( $contact_form, &$abort, $submission ) {
            // Getting user input through the your-email field
            $your_email = $submission->get_posted_data( 'email-newsletter' );
    
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://mywebsite.com/MAIL=' . $your_email);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_exec($ch);
            curl_close($ch);
    
            $abort = true;
        },
        10, 3
    );

    When I submit the form, the following error displays in the console:

    {code: 'invalid_json', message: 'The response is not a valid JSON response.'}

    And the submission message doesn’t display (the sending icon keeps turning).

    Should I add something else?

    Regards,

    Clara.

    • This topic was modified 2 years, 11 months ago by arbremojo.
Viewing 1 replies (of 1 total)
  • Thread Starter arbremojo

    (@arbremojo)

    I’m sorry I found the solution!

    add_action( 'wpcf7_before_send_mail',
        function( $contact_form, &$abort, $submission ) {
            // Getting user input through the your-email field
            $your_email = $submission->get_posted_data( 'email-newsletter' );
            $url = 'https://mywebsite.com/MAIL=' . $your_email;
    
            $response = wp_remote_post($url);
        },
        10, 3
    );
Viewing 1 replies (of 1 total)
  • The topic ‘cURL throws invalid_json’ is closed to new replies.