· 6 years ago · Jul 25, 2019, 07:56 AM
1function sendToCRM($post){
2
3 $post['utm_source'] = (isset($post['utm_source']) ? $post['utm_source'] : '');
4
5 // * update the client accessKey & SecretKey here *//
6 $credentials = array(
7 'accessKey' => '',
8 'secretKey' => ''
9 );
10
11 $url = 'https://api-in21.leadsquared.com/v2/LeadManagement.svc/Lead.Capture?'.http_build_query($credentials);
12
13 $curl = curl_init();
14
15 $data = array(
16 array(
17 'Attribute' => 'FirstName',
18 'Value' => $post['name'],
19 ),
20 // array(
21 // 'Attribute' => 'LastName',
22 // 'Value' => 'Lee',
23 // ),
24 array(
25 'Attribute' => 'EmailAddress',
26 'Value' => $post['email'],
27 ),
28 array(
29 'Attribute' => 'Phone',
30 'Value' => $post['phone'],
31 ),
32 array(
33 'Attribute' => 'Source',
34 'Value' => $post['utm_source'],
35 ),
36 array(
37 'Attribute' => 'Message',
38 'Value' => $post['message'],
39 )
40
41 // array(
42 // 'Attribute' => 'ProspectID',
43 // 'Value' => 'xxxxxxxx-d168-xxxx-9f8b-xxxx97xxxxxx',
44 // ),
45 // array(
46 // 'Attribute' => 'SearchBy',
47 // 'Value' => 'Phone'
48 // )
49 );
50
51 $json = json_encode($data, 128);
52
53 $ch = curl_init( $url );
54 curl_setopt( $ch, CURLOPT_POST, 1);
55 // curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($_data));
56 curl_setopt( $ch, CURLOPT_POSTFIELDS, $json);
57 curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
58 curl_setopt( $ch, CURLOPT_HEADER, 0);
59 curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "cache-control: no-cache"));
60 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
61
62 $response = curl_exec( $ch );
63
64 $result = json_decode($response);
65 // if($result->Status == 'Success')
66 // echo 'true';
67 // else
68 // echo 'false';
69 return $response;
70}