send_leads.php 5.27 KB
<?php

class PostData
{
    public function callback()
    {

        $channel = $_COOKIE['cstm_ppc_channel'];
        $campaign = $_COOKIE['cstm_ppc_campaign'];
        $placement = $_COOKIE['cstm_ppc_placement'];
        $keyword = $_COOKIE['cstm_ppc_keyword'];
        $device = $_COOKIE['cstm_ppc_device'];
        $gclid = $_COOKIE['gclid'];
        $lead_source = $_COOKIE['lead_source'];

        $ip = $_SERVER['REMOTE_ADDR'];

        $fname = $_REQUEST['fname'];
        $lname = $_REQUEST['lname'];
        $email = $_REQUEST['email'];
        $mobile = str_replace(' ', '', $_REQUEST['mobile']);
        //$projectname = $_REQUEST['projectname'];
        $source = $_REQUEST['source'];
        $message = $_REQUEST['message'];
        $conf = $_REQUEST['select_option_1'];
        $site_visit = $_REQUEST['select_option_2'];
        //$country_code = $_REQUEST['country_code'];
        $name = $fname . ' ' . $lname;
        $fullmobile = "91" . $mobile;

        $postFields = "entry.449648499=" . $name;
        $postFields .= "&entry.1379833540=" . $email;
        $postFields .= "&entry.758332158=" . $fullmobile;
        $postFields .= "&entry.1900106466=" . $message;
        $postFields .= "&entry.1693361781=" . $source;


        $postFields .= '&entry.1830911442=' . urlencode($_COOKIE['cstm_ppc_campaign']);
        $postFields .= '&entry.939490048=' . urlencode($_COOKIE['cstm_ppc_channel']);
        $postFields .= '&entry.729166844=' . urlencode($_COOKIE['cstm_ppc_keyword']);
        $postFields .= '&entry.839903606=' . urlencode($_COOKIE['cstm_ppc_placement']);
        $postFields .= '&entry.2003337495=' . urlencode($_COOKIE['cstm_ppc_device']);
        $postFields .= '&entry.399907321=' . urlencode($_COOKIE['cstm_ppc_medium']);
        $postFields .= '&entry.1966964226=' . urlencode($_COOKIE['gclid']);
        $postFields .= '&entry.599794443=' . $conf;
        $postFields .= '&entry.1354448406=' . $site_visit;
        $postFields .= '&entry.2132069230=' . $ip;

        $ch3 = curl_init();
        curl_setopt($ch3, CURLOPT_URL, "https://docs.google.com/forms/u/0/d/e/1FAIpQLSf1umE0Ufk6C5pCRFeygSVIxCoF880P4Tz62kJ8fG8ErXYOLQ/formResponse");
        curl_setopt($ch3, CURLOPT_POST, 1);
        curl_setopt($ch3, CURLOPT_POSTFIELDS, $postFields);
        curl_setopt($ch3, CURLOPT_HEADER, 0);
        curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
        $result3 = curl_exec($ch3);



               $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://accounts.zoho.in/oauth/v2/token?refresh_token=1000.97ccf5a662503908f7386aac639d3f8c.c4cf3294129c81da18181996e55af4c7&client_id=1000.E5Q33CVDAS2U8SO2V12N02F8R8R0OK&client_secret=c71c44d0167124d3557369ca49245027f83add1c07&grant_type=refresh_token',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_HTTPHEADER => array(
                'Cookie: _zcsr_tmp=103f0b91-b3ef-410f-93e1-e24a5038c5c0; iamcsr=103f0b91-b3ef-410f-93e1-e24a5038c5c0; zalb_6e73717622=13e67ac15bc4d3ece130966123511df7'
            ),
        ));

        $response = curl_exec($curl);

        $json = json_decode($response);

        //echo 'token- ' . $json->access_token;
        $access_token = $json->access_token;
        // var_dump( $access_token);

        if ($lead_source == "") {

            $lead_source = "Google Ads";
        }

        if (!$access_token == '' || !$access_token == null) {

            $data = array(
                "data" => array(
                    array(
                        "Campaigner" => "Realatte",
                        "Last_Name" => $name,
                        "First_Name" => "",
                        "Phone" =>  $fullmobile,
                        "Email" => $email,
                        "State" => "",
                        "Lead_Source" => $lead_source,
                        "Campaign_Project" => "Ecocity",
                        "Lead_Status" => "New Lead"
                    )
                )
            );

            $json_input = json_encode($data, true);

            $curl = curl_init();

            curl_setopt_array($curl, array(
                CURLOPT_URL => 'https://www.zohoapis.in/crm/v2.1/Leads',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => $json_input,
                CURLOPT_HTTPHEADER => array(
                    'Authorization: Bearer ' . $access_token,
                    'Content-Type: application/json',
                    'Cookie: _zcsr_tmp=db4f4e23-ce1f-43c6-8710-3b73b562a77e; crmcsr=db4f4e23-ce1f-43c6-8710-3b73b562a77e'
                ),
            ));

            $response = curl_exec($curl);

            curl_close($curl);
            // echo $response;
            // var_dump($response);
            // die;


        }


   
        // do not delete
        return true;
    }
}