The 'submit data to a form' isn't working in PHP


Our users start on HubSpot, are transferred to our server for data processing, then sent back to HubSpot. Problem: HubSpot doesn’t receive most of the user’s data sent back.

We are sending user data back to HubSpot using the PHP code given in: (shown below).

The only data that is subsequently on HubSpot is the user’s email address and company - the rest, including the cookie data, disappears. It never shows up in the analytics.

The code’s that’s running on our server is given below.

Any idea what’s wrong?



The PHP code is:

// -------------- send user contact details to hubspot
if (isset($_COOKIE[‘hubspotutk’]) && $_COOKIE[‘hubspotutk’] == ‘yes’) {
$hubspotutk = $_COOKIE[‘hubspotutk’]; //grab the cookie from the visitors browser.
if (isset($_SERVER[‘REMOTE_ADDR’]) && $_SERVER[‘REMOTE_ADDR’] == ‘yes’) {
$ip_addr = $_SERVER[‘REMOTE_ADDR’]; //IP address too.
$hs_context = array(
‘hutk’ => $hubspotutk,
‘ipAddress’ => $ip_addr,
‘pageUrl’ => ‘’,
‘pageName’ => ’ Demo - with your PDF’
$hs_context_json = json_encode($hs_context);

if (isset($_POST['firstname'])){
if (isset($_POST['lastname'])){
if (isset($_POST['company'])){

//Need to populate these variable with values from the form.
$str_post = "firstname=" . urlencode($firstname)
    . "&lastname=" . urlencode($lastname)
    . "&email=" . urlencode($emailTO)
    . "&company=" . urlencode($company)
    . "&hs_context=" . urlencode($hs_context_json); //Leave this one be

$formGuid="junk... contact me for details ";
//replace the values in this URL with your portal ID and your form GUID
//$endpoint = '{portalId}/{formGuid}';
$endpoint = '' . $portalId . '/' . $formGuid;
//echo "endpoint: " . $endpoint;

//send the info
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded'
@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 . " " . $response;


@Jon Do you receive any kind of error code or a http response code?


We don’t log it - but could do for testing if helpful.

I have to assume some data is getting out - otherwise HubSpot
wouldn't record email addresses.



@Jon if you could un-comment out your echo at the bottom of your script that would be helpful. Then we can see the status code and the response.


We’re only running a live server at present.

So we'll have a look at what's practical and get back to you




We un-commented and ran a couple of samples.

The return code was 204.



@Jon to confirm if you were to have a completely new contact submit on the form you only get their email address?



You can see I tried one from my home email last night
(<a class="moz-txt-link-abbreviated" href=""></a>)


Jon Goldhill

    Director, Zanran Ltd

    +44 (0) 20 7354 6333 (direct)


@Jon I am not sure what you posted above. In the contact record on the Hubspot platform in your portal do you get all the information or just the email?


Sorry - I assumed you could see the data on our account.

In the contact record it <u>only </u>shows the email address.

First name, last name and company are missing - as well as the
cookie details which would have included the initial page views.



@Jon With our your portal ID I cannot.

Where does $emailTO come from?

I notice that you pass that variable in differently then the rest. The rest are all in this block. If you try and echo firstname or lastname before you make the curl request is it populated or blank?

$firstname=''; if (isset($_POST['firstname'])){ $firstname=$_POST['firstname']; } $lastname=''; if (isset($_POST['lastname'])){ $lastname=$_POST['lastname']; } $company=''; if (isset($_POST['company'])){ $company=$_POST['company']; }


Just back from a meeting. I’ll have to check this out tomorrow


Jon Goldhill
Director, Zanran Ltd
+44 (0) 20 7354 6333 (direct)



Firstly, we use the variable name $emailTO earlier in the code.

The block you mention is just initialising the variables.

Before I do the checks you suggest, can you confirm that the
variable names (lastname, firstname, company) are correctly spelt
for what you expect at the HubSpot end?




Hi again,

Can you also send us a correct string that we can put into this

@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);

- we can then find out whether the problem is at our end or yours.




@Jon, Yes they are correctly spelled out to reflect the internal name of those contact properties.

Here is a link that would provide you an example of a string to post and how to set up the call.

Can you confirm that firstname actually has a value before you send it to hubspot? You might be just sending a blank string over.



Great progress!  We can now see FirstName, LastName etc in the

(It was an inconsistent use of upper/lower case).

However we still can't track a Contact's journey through the HubSpot

We see the pages they've gone to AFTER they've been onto our server
and returned to HubSpot.

But we don't capture anything that happened prior to that.

We had added the JavaScript code to our server code:

        &lt;!-- Start of HubSpot Embed Code --&gt;

            &lt;script type="text/javascript" id="hs-script-loader"
async defer src="//"&gt;&lt;/script&gt;

        &lt;!-- End of HubSpot Embed Code --&gt;

Is there something else we need to do?



Jon Goldhill

    Director, Zanran Ltd

    +44 (0) 20 7354 6333 (direct)


@Jon Just so I understand after a user submits their email address to you, you send it over to hubspot. When a contact record is created you don’t see any of the page view history? A contact record won’t be created until we get an email address but you should see the existing page views that are all logged on the cookie on the machine. How are you testing this? Are you clearing any cookies?



I see the page view history for AFTER the email address etc are

But it isn't linked to the page views for when the user first landed
on the HubSpot site.

So, for example, I have no idea which page the user originally
landed on.

I was expecting to see the earlier page views as part of the
timeline that you see after clicking on the Contact Name.

An example is attached.

For this example, I went to several pages on the HubSpot server,
then to our Demo server and back again.

You can only see the last set of page views.

We're not knowingly clearing anything on the HubSpot server or the
client machine.


Jon Goldhill

    Director, Zanran Ltd

    +44 (0) 20 7354 6333 (direct)


@Jon That doesn’t seem right. When it comes to an issue in the product team our support team would probably know best. I would contact them and see if they know what is going on. You can reach them at or from within your portal. Please let me know if you get anywhere or if not so I can reach out to them if need be. Let me know if you run into anything else from an API standpoint.


OK - I’ve done that.

They couldn't see what was wrong either, so the helpful woman I
spoke to (Taylor) set up a new tech ticket #468601.

You might come across it.