Php CURL-没有响应也没有错误

Php CURL-没有响应也没有错误,php,curl,Php,Curl,我希望有人能帮助我,因为我没有得到回应,没有错误,也没有迹象表明为什么我的卷发在这里不起作用。我四处搜索并添加了一个忽略SSL的子句(SSLVerify设置为false),并尝试了多种方法来获得响应 有人能给我指一下正确的方向吗 谢谢 <?php function sendContactInfo() { //Process a new form submission in HubSpot in order to create a new Contact. $hubspotutk = $

我希望有人能帮助我,因为我没有得到回应,没有错误,也没有迹象表明为什么我的卷发在这里不起作用。我四处搜索并添加了一个忽略SSL的子句(SSLVerify设置为false),并尝试了多种方法来获得响应

有人能给我指一下正确的方向吗

谢谢

<?php
function sendContactInfo() {

//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/234423/4a282b6b-2ae2-4908-bc82-b89874f4e8ed';

$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);
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = @curl_exec($ch);
$info = @curl_getinfo($ch);
@curl_close($ch);
}

echo sendContactInfo();
echo $response;
print_r($info);
?>

sendContactInfo是一个函数,但其使用方式与函数不同

无法访问函数内部使用的变量。它还需要返回一些东西

更改:

$response = @curl_exec($ch);


1.不能在函数外部打印函数内部定义的变量值,如下所示:

function sendContactInfo() {

 $response = @curl_exec($ch);

 $info = @curl_getinfo($ch);

}

echo $response;

print_r($info);
function sendContactInfo() {

 $response = @curl_exec($ch);

 $info = @curl_getinfo($ch);

 return $response;

 //or return $info;, when you want to get array values from @curl_getinfo

}

print_r(sendContactInfo());
但您可以打印值,以便:

function sendContactInfo() {

 $response = @curl_exec($ch);

 $info = @curl_getinfo($ch);

 echo $response;

 print_r($info);

}

sendContactInfo();
2.当您想要运行函数并获取after值时,请使用“return”,如下所示:

function sendContactInfo() {

 $response = @curl_exec($ch);

 $info = @curl_getinfo($ch);

}

echo $response;

print_r($info);
function sendContactInfo() {

 $response = @curl_exec($ch);

 $info = @curl_getinfo($ch);

 return $response;

 //or return $info;, when you want to get array values from @curl_getinfo

}

print_r(sendContactInfo());

添加错误处理。你没有<代码>$response=curl\u exec($ch);如果($response==false){die(curl_error($ch));}。永远不要抑制错误,尤其是当您知道代码不工作时。你基本上闭上眼睛,用手指捂着耳朵,开始大喊“Nananan”,特别是忽略了PHP可以帮助你找出问题所在的一切。
curl\u setopt($ch,CURLOPT\u VERBOSE,true)
可能会给你一些有用的信息。