0

Magento の成功ページで Hubspot にフォームを送信しようとしています。変数 $str_post に必要な情報がすべて含まれていることを確認しました。残念ながら、$response が空である理由を特定できません。CURL 接続が行われていないようですが、その理由を特定できないようです。ページをロードする以外に、CURL 接続をトリガーするために必要なことはありますか?

URL から GUI/フォーム ID を削除したことに注意してください。

<?php
//Process a new form submission in HubSpot in order to create a new Contact.

$hubspotutk = $_COOKIE['hubspotutk'];  //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR'];  //IP address too.
$hs_context = array(
        'hutk' => $hubspotutk,
        'ipAddress' => $ip_addr,
        'pageUrl' => 'https://www.myfoodstorage.com/onestepcheckout/',
        'pageTitle' => 'MyFoodStorage.com Cart Checkout'
    );
$hs_context_json = json_encode($hs_context);

//Need to populate these varilables with values from the form.
$str_post = "firstname=" . urlencode($firstname)
        . "&lastname=" . urlencode($lastname)
        . "&email=" . urlencode($email)
        . "&phone=" . urlencode($telephone)
        . "&address=" . urlencode($street)
        . "&city=" . urlencode($city)
        . "&state=" . urlencode($region)
        . "&country=" . urlencode($country)
        . "&hs_context=" . urlencode($hs_context_json);  //Leave this one be :)

 //replace the values in this URL with your portal ID and your form GUID
$endpoint = 'https://forms.hubspot.com/uploads/form/v2/GUI-ID/FORM-ID';

$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('application/x-www-form-urlencoded'));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);  //Log the response from HubSpot as needed.
@curl_close($ch);
echo $response;

?>
4

1 に答える 1

0

Forms API への送信が成功すると、204 (No Content) 応答が返されるため、応答の本文には何もありません。curl_getinfo を使用してステータス コードを取得できます。

$response = @curl_exec($ch);  //Log the response from HubSpot as needed.
echo @curl_getinfo($ch, CURLINFO_HTTP_CODE);
@curl_close($ch);
echo $response;
于 2013-02-28T21:46:01.100 に答える