这是我的表格。
<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": "hello@projectmap.io"
}'
答案 0 :(得分:1)
我希望这会奏效,
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);
}