2016-06-11 58 views
0

這是我的表單。如何設置捲曲爲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> 

如何將此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]" 
    }' 

回答

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

我需要在形式上做些什麼? –

+0

@SirenBrown您的表單部分包含兩個輸入,姓名和電子郵件,你可以告訴我你是否使用姓名字段? –

+0

是名稱和電子郵件作爲名稱字段在PHP中發送郵件。 –