HubSpot form submission via PHP cURL not reflecting data despite 204 response

I’m having trouble with a HubSpot form submission using PHP cURL. Here’s the deal:

  • I’m using the HubSpot form upload endpoint with the correct portal ID and form GUID
  • The request returns a 204 status code, which should mean success
  • But no data shows up in HubSpot after submission
  • This works fine on my local machine, but not on the server
  • Both environments have the same code

I’ve created a function to handle the API call:

function sendToHubSpot($formData) {
    $hubspotUrl = 'https://forms.hubspot.com/uploads/form/v2/' . PORTAL_ID . '/' . FORM_GUID;
    
    $curl = curl_init();
    curl_setopt_array($curl, [
        CURLOPT_URL => $hubspotUrl,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $formData,
        CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false
    ]);
    
    $response = curl_exec($curl);
    $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);
    
    return $statusCode;
}

Any ideas what could be causing this issue on the server? I’m stumped!

hey oliviac, this sounds frustrating! have u checked if ur server’s ip is whitelisted on hubspot’s end? sometimes they block ips for security. also, maybe try enabling curl_error() to see if there’s any hidden errors. good luck!

I’ve dealt with similar HubSpot form submission issues before, and it can be quite tricky to debug. One thing that helped me was to implement more robust error handling and logging. Try wrapping your cURL request in a try-catch block and log any exceptions. Also, consider logging the full request and response data.

Another aspect to look at is the server’s outbound connections. Some hosting environments restrict outbound requests. Check with your hosting provider to ensure there are no firewall rules or network policies blocking connections to HubSpot’s servers.

Lastly, verify that your server’s time is correctly synchronized. I once had a case where incorrect server time caused API requests to fail silently. An NTP sync resolved the issue. Hope this helps!

yo oliviac, that’s a tricky one! have u tried adding some debug logging to see wats happening on the server? maybe dump the $formData and full response somewhere. also, check if theres any difference in PHP versions between ur local and server. sometimes that can mess things up. good luck!

I encountered a similar issue when implementing HubSpot form submissions. One crucial aspect to check is the SSL certificate validation on your server. While disabling SSL verification (as in your code) might work locally, it’s not recommended for production environments. Instead, ensure your server has up-to-date CA certificates and remove the CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options. Additionally, double-check that all form fields match exactly with those defined in your HubSpot form, including any hidden fields. Mismatched field names can lead to silent failures. Lastly, consider implementing detailed logging on your server to capture the full request and response data for troubleshooting.