简体   繁体   English

如何将curl设置为php

[英]How to set curl into php

This is my form. 这是我的表格。

<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>

How can I set this curl code into php for this form? 我怎样才能将这种curl代码设置为此形式的php?

Create a new User Users can be created or updated via a POST method to https://api.intercom.io/users , which accepts a JSON object describing the user. 创建新用户可以通过POST方法将用户创建或更新为https://api.intercom.io/users ,该方法接受描述用户的JSON对象。

Example request: 请求示例:

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"
  }'

I hope this will work, 我希望这会起作用,

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);
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM