0
我正在嘗試在Magento的成功頁面上將表單提交給Hubspot。我已經確認變量$ str_post包含所有需要的信息。不幸的是,我無法確定爲什麼$響應是空的。似乎CURL連接沒有被做,但我似乎無法確定爲什麼。除了加載頁面之外,我還需要做些什麼才能觸發CURL連接?Magento&Hubspot - 成功提交表單
請注意我已經從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;
?>
首先我希望這是在塊中,而不是在模板(.phtml)文件中。其次,你用@符號抑制了所有的錯誤報告,所以你永遠不會得到一個PHP錯誤。第三,看看curl_error():http://php.net/manual/en/function.curl-error.php – 2013-02-27 22:57:52