<?php

if(isset($_REQUEST['firstname']) && $_REQUEST['firstname'] != "") $firstname=$_REQUEST['firstname'];
if(isset($_REQUEST['phoneno']) && $_REQUEST['phoneno'] != "") $phoneno=$_REQUEST['phoneno'];
if(isset($_REQUEST['emailid']) && $_REQUEST['emailid'] != "") $emailid=$_REQUEST['emailid'];
if(isset($_REQUEST['companyid']) && $_REQUEST['companyid'] != "") $companyid=$_REQUEST['companyid'];
if(isset($_REQUEST['cityid']) && $_REQUEST['cityid'] != "") $cityid=$_REQUEST['cityid'];
if(isset($_REQUEST['pincode']) && $_REQUEST['pincode'] != "") $pincode=$_REQUEST['pincode'];

$msg="Name:".$firstname."<br>Company Name:".$companyid."<br>City:".$cityid."<br>PIN Code:".$pincode."<br>Phone No :".$phoneno."<br>Email id: ".$emailid;

SendGridMail('shankar.surya@indiamart.com',$msg);
SendGridMail('keegan.pereira@unilever.com',$msg);
SendGridMail('Mini.Birdsturgeon@unilever.com',$msg);

header( "refresh:5;url=https://www.hul.co.in/brands/home-care/domex.html" );
function sendgridmail($Receiver_email,$mail_body)
    {
        $category = "DOMEX_LEADS";
        $Subject='Lead Generated from IndiaMART for Ad Campaign';
        $key="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";
        $sent_date=date('d-m-Y', time());
        $umailid = "DOME-$sent_date-".rand(10, 99);  


        $from_email = 'shankar.surya@indiamart.com';
        $fromName="IndiaMART";
        $umail='DOME';
        if($key != ""){

                $categories_key_array = Array(
                $category
                );

                //var_dump($unique_args);
                $indiamart_email = $from_email;
                $reply_to = $replyTo;
                $from_name=$fromName;
                $toarr = explode("," , $Receiver_email);  
                if(array_key_exists(1,$toarr)){
                $to_key_array = Array(0 => Array("email" => $toarr[0]),1 => Array("email" => $toarr[1]));
                }else{
                $to_key_array = Array(0 => Array("email" => $toarr[0]));
                }

                $reply_to_key_array = Array("email" => $reply_to); 

                $request_body = Array(
                "personalizations" => Array
                (
                0 => Array
                (
                "to" => $to_key_array,
                "subject" => $Subject,
                )
                ),
                "from" => Array
                (
                "email" => $indiamart_email,
                "name" => $from_name
                ),
                "content" => Array
                (
                0 => Array
                (
                "type" => "text/html",
                "value" => $mail_body
                )
                ),

                "categories" => $categories_key_array,
                );



                $curl = curl_init();
                // var_dump(json_encode($request_body));
                curl_setopt_array($curl, array(
                CURLOPT_URL => "https://api.sendgrid.com/v3/mail/send",
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 5,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "POST",
                CURLOPT_POSTFIELDS => json_encode($request_body),
                CURLOPT_HTTPHEADER => array(
                "authorization: Bearer $key",
                "content-type: application/json"
                ),
                )
                );
                //var_dump($request_body);
                $response = curl_exec($curl);
                //var_dump($response);
                //echo "\n";
                $err = curl_error($curl);
                $errno = curl_errno($curl);
                $status = curl_getinfo($curl);
                // var_dump($err);
                curl_close($curl);

        }
}
?>
<div style="padding:5px; margin: 0 auto; text-align: center; font-family:'open sans', arial; font-size: 30px;"><h1>Thank You!</h1></div>

<div style="font-family:'open sans', arial; font-size:16px; text-align: center; line-height: 25px; max-width: 100%; width:600px; padding: 10px; margin: 0 auto;">We appreciate your interest in the <strong>Domex Range of cleaning and disinfection solutions</strong>. <br>
     Our team will reach out to you shortly to explain our products portfolio and any current offers or schemes available.</div>
