I am using this code to pass all fields :
$formGuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$fields = array(
'fields' => [
array('name'=>'firstname','value'=>$_POST['first_name']),
array('name'=>'company','value'=>$_POST['company']),
]
);
$hubspotutk = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR']; //IP address too.
$pageUrl = $_SERVER['HTTP_REFERER']; //IP address too.
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $ip_addr,
'pageUrl' => $pageUrl,
'pageName' => 'Hybrent Test'
);
$hs_context_json = json_encode($hs_context, true);
$fields['hs_context'] = $hs_context_json;
$endpoint = 'https://api.hsforms.com/submissions/v3/integration/submit/xxxxxxxx/'.$formGuid;
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields)
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
echo $status_code;
@curl_close($ch);