How to integrate website with CRM?

Need to integrate crm system with the website, so send the forms from the website created transaction in crm
I went through all the widgets, all very uncomfortable. Want to save your form. On the Internet I found this solution, saw it on many sites
Could you tell me where exactly to insert? in shape or just in the website. I would be grateful for a detailed explanation

code:
<?php

$site_name = $_SERVER["HTTP_REFERER"];

//Path of the site to create different labels for amoCRM
$site_path = str_replace($_SERVER['HTTP_HOST'] , ", $_SERVER['HTTP_REFERER']);
$site_path = str_replace('http://' , ", $site_path);
$site_path = str_replace('/' , ", $site_path);

//Generated from the City by IP
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$details1 = $details--->region;
$details2 = $details->city;
$geo= ".$details1.', '.$details2.";

//Generated data to add them to amoCRM
$contact = array(
'name'=>$data['name'],
 'tags' => 'Application site '. $site_path,
'responsible_user_id'=>$manager,
'text'=>12488185,
'custom_fields'=>array(
array(
'id'=>$custom_fields['EMAIL'],
'values'=>array(
array(
'value'=>$data['email'],
'enum'=>'WORK'
)
)
),
array(
'id'=>1755674,
'values'=>array(
array(
 'value'=> $geo
)
)
)

)
);

//Collect data from fields
if(!empty($data['phone']))
$contact['custom_fields'][]=array(
'id'=>$custom_fields['PHONE'],
'values'=>array(
array(
'value'=>$data['phone'],
'enum'=>'OTHER'
)
)
);

if(!empty($data['web']))
$contact['custom_fields'][]=array(
'id'=>$custom_fields['Website'],
'values'=>array(
array(
'value'=>$data['web']
)
)
);

$set['request']['contacts']['add'][]=$contact;

#Generated link to request
$link='https://'.$subdomain.'.amocrm.ru/private/api/v2/json/contacts/set';
$curl=curl_init(); #save the session handle cURL
#Set required options for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($set));
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl,THIS,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);

$out=curl_exec($curl); #Initiate a request to an API and store the response in a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
CheckCurlResponse($code);

/**
 * Data received in JSON format, so, to obtain read data,
 * we have to translate the response into a format understandable PHP
*/
$Response=json_decode($out,true);
$contact ID=$Response['response']['contacts']['add'][0]['id'];

$contacts['request']['contacts']['update']=array(
array(
'id'=>$contact ID,
 'last_modified' => time(),
'custom_fields'=>array(
#Project
array(
'id'=>$custom_fields['EMAIL'],
'values'=>array(
array(
'value'=>$data['email'],
'enum'=>'WORK'
)
)
)
)
 ) //possible extra comma
);

#Generated link to request
$link='https://'.$subdomain.'.amocrm.ru/private/api/v2/json/contacts/set';

$curl=curl_init(); #save the session handle cURL
#Set required options for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($contacts));
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl,THIS,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);

$out=curl_exec($curl); #Initiate a request to an API and store the response in a variable

// Set the task
$tasks['request']['tasks']['add']=array(
array(
 'element_id'=>$contact ID,// ID of the created transaction ($lead_id) or contact ($contact ID)
 'element_type'=>1, // Type: 1 - contact, 2 - trade
 'task_type'=>52426, #Meeting
 // 'text'=>'Application '. $site_name . '' . $data['massage'] . '' . $data['action'] ,
 'text'=>'Application' . $site_name . '' . $data['action'] . '' . $data['massage'],
'responsible_user_id'=>$manager,
 // user Dima
 'complete_till'=>time()+600,// 10 minutes to complete

)
);

#Generated link to request
$link='https://'.$subdomain.'.amocrm.ru/private/api/v2/json/tasks/set';

$curl=curl_init(); #save the session handle cURL
#Set required options for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($tasks)); // Encode the array in JSON format
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
//curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl,THIS,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);

$out=curl_exec($curl); #Initiate a request to an API and store the response in a variable
curl_close($curl);

//
// const VERSION = '0.0.1';
//
// private static $api_key = 'BLAH BLAH';
// private static $list_id = 'b36623ad35';
// private static $test_list_id = 'fdbb5d7d9f';
// private static $email;
// private static $is_test_subscribe = false;
//
//
// static function initialize($config=array())
// {
// CMS::add_component('MailChimpSync', new CMS_Mapper());
// }
//
//
// private static function get_datacenter_code()
// {
// return preg_match('{-(.*)$}', self::$api_key, $m) ? $m[1] : false;
// }
//
// private static function get_api_url($section, $method)
// {
// if ($datacenter_code = self::get_datacenter_code()) {
// $base_api_url = 'https://'.$datacenter_code.'.api.mailchimp.com/2.0/';
// return $base_api_url.$section.'/'.$method;
// }
// return false;
// }
//
//
// public static function build_mailchimp_object()
// {
// $result = new stdClass();
// $result->apikey = self::$api_key;
// $result->id = self::$is_test_subscribe ? self::$test_list_id : self::$list_id;
// $result->email = self::build_mailchimp_email_object();
//
// $result_merge_vars = new stdClass();
// $result_merge_vars->mc_language = 'EN';
//
// $result->merge_vars = $result_merge_vars;
// return $result;
// }
//
//
// public static function build_mailchimp_email_object()
// {
// $email_obj = new stdClass();
// $email_obj->email = self::$email;
// $email_obj->euid = md5(self::$email);
// $email_obj->leid = self::$list_id;
// return $email_obj;
// }

//unisender cUrl subscrible subscription

// Your API access key (from your Personal account)
$api_key = "BLAH BLAH";

// Data about the new subscriber
$user_email = $_POST['email'];
$user_name = $_POST['name'];

$user_lists = "482917";
$user_tag = "noread";
$str= $_POST['phone'];
$phone= preg_replace('/[^0-9]/', ", $str);

// Create a POST request
$POST = array (
 'api_key' => $api_key,
 'list_ids' => $user_lists,
 'fields[email]' => $user_email,
 'fields[Name]' => $user_name,
 'fields[phone]' => $phone,
 'tags' => $user_tag,
 'double_optin' => '3',
 'overwrite' => '1'
);

// Set connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL,
'https://us1.api.mailchimp.com/3.0/lists');
$result = curl_exec($ch);

if ($result) {
 // We response the API server
 $jsonObj = json_decode($result);

 if(null===$jsonObj) {
 // Error in received response
 //echo "Invalid JSON";

}
 elseif(!empty($jsonObj->error)) {
 // Error adding the user
 // echo "An error occured:" . $jsonObj->error . "(code: ". $jsonObj->code . ")";

 } else {
 // New user added successfully
 //echo "Added. ID is " . $jsonObj->result->person_id;

}
} else {
 // Error connecting to API server
 //echo "API access error";
}

?>

June 27th 19 at 15:16

Find more questions by tags CRM