这是我的表格。
<form action="mail.php" method="post">
<label class="form-label" for="name">Full Name</label>
<input class="user" type="text" name="name" id="name">
<label class="form-label" for="email">Email Id</label>
<input class="email" type="email" name="email" id="email">
</form>
如何将这种curl代码设置为此形式的php?
创建新用户可以通过POST方法将用户创建或更新为https://api.intercom.io/users
,该方法接受描述用户的JSON对象。
请求示例:
curl https://api.intercom.io/users \
-X POST \
-u app_id:api_key \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' -d '
{
"email": "[email protected]"
}'
我希望这会起作用,
if(isset($_POST['email']))
{
$url = 'https://api.intercom.io/users';
$array=array('email'=>$_POST['email']);
$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
curl_setopt($ch, CURLOPT_USERPWD, 'app_id:api_key');
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句