Siren Brown Siren Brown - 5 months ago 24
PHP Question

How to set curl into php

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


This is my form.

How can I set this curl code into php for this form?

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.

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

Answer

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