<?php 
if(isset($_POST['submit'])){
  
  
  
    $to = "deeksha@globaltradeplaza.com"; // this is your Email address
    // $to = "abhishek.sharma@globaltradeplaza.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    
   
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $address = $_POST['address'];
    $product = $_POST['product'];
    $message = $_POST['message'];
    
    // save lead to db
$host = "localhost";
$username = "collinsg_camgtpu";
$password = "dh+z9*R*V0mR";
$database = "collinsg_camgtpu";

try {
    // Create a PDO database connection
    $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);

    // Set the PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Retrieve form data
    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $address = $_POST["address"];
    $product = $_POST["product"];
    

    // SQL query to insert the lead into the database
    $sql = "INSERT INTO campaignleads (customername, customeremail, customerphone,customercountry,customerproduct) VALUES (:name, :email, :phone,:address,:product)";

    // Prepare the SQL statement
    $stmt = $pdo->prepare($sql);

    // Bind parameters
    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':email', $email, PDO::PARAM_STR);
    $stmt->bindParam(':phone', $phone, PDO::PARAM_STR);
    $stmt->bindParam(':address', $address, PDO::PARAM_STR);
    $stmt->bindParam(':product', $product, PDO::PARAM_STR);

    // Execute the statement
    $stmt->execute();

    // echo "Lead inserted successfully.";
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}

// Close the database connection
$pdo = null;
    // save lead to db
} 
   
?>


<?php	
	if(empty($_SERVER['HTTP_REFERER'])) {
		header("Location:https://campaigns.globaltradeplaza.com/");
	}
	if(!empty($_POST['email'])) {

		$postData="";
		foreach ($_POST as $key => $value) {
			if(!empty($postData)) {
				$postData .="||";
			}
			$postData .= $key."~~".$value;
		}

		$data_string = json_encode($postData); 
		$headers = array ("Authorization:SG#^TP152K@NP#RG5R","Content-Type: application/json");  

		$ch = curl_init();  
		curl_setopt($ch, CURLOPT_URL, "https://webdx.webixytools.com/catalog/contactus_inq.php");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
		$result = curl_exec($ch);
		curl_close ($ch);
// 		$mailTo = "go13019@gmail.com";
$mailTo = $_POST['email'];
		$fromMail = "deeksha@globaltradeplaza.com";
		$mailSubject = "Welcome to Global Trade Plaza!";
		
		$emailmsg = '
		<html>
		<head>		
		<title>Global Trade Plaza</title>
		</head>
		<body>
		<table class="main_wrap" cellpadding="0" cellspacing="0" align="center" style=" width: 50%; max-width: 100%; font-family: Roboto, sans-serif; font-size:14px;  line-height:18px; border:1px solid #cccccc; color:#333333;">
		<tr>
		<td style="color:#333333;" valign="top">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size:16px; font-family: Roboto, sans-serif; line-height:18px; color:#333333; padding:0px 10px 10px 10px; border-bottom: 1px solid #eee;">
		<tr>
		<td style="padding-left:20px;  padding-top:5px; padding-bottom:10px;">
		<a href="https://globaltradeplaza.com/"><img src="https://campaigns.globaltradeplaza.com/image/GTP-logo-Trade-Mark.png" width="180" height="40" alt="Global Trade Plaza" title="Global Trade Plaza
		"></a></td>		
		</tr> 				
		</table>
		<div style="padding-top:10px;padding-bottom:10px; line-height:18px; ">
		<div style="font-weight: bold; margin-bottom: 10px; font-size: 14px; padding-left: 10px; padding-right: 10px;"><span align="right" style="color:#fff; line-height:20px;">Dear  </span> '.$_POST['name'].' </div>

		<div style="padding-bottom:10px; padding-left: 10px; padding-right: 10px; line-height: 22px;"> 
		<p>It is a pleasure to be at your service! We are thrilled to receive your message and are excited to have the opportunity to work with you.
        </p>
        <p>
        Our team is dedicated to providing you with exceptional service and cut-to-the-chase strategies for your business needs. Please feel free to reply to this email or contact us directly via WhatsApp, if you have any immediate questions or requirements.

        </p>
		<b>We are looking forward to our future partnership.</b>
		</div>
		<div>		
		
		<table cellpadding="0" cellspacing="0" width="100%" style=" padding-left: 10px; padding-right: 10px; font-size:14px; font-family: Roboto, sans-serif; color:#333333; text-align:left;">
		<tr>
		<td valign="top" width="55%">
		<div style="font-weight:bold; padding-bottom:5px; color:#0066cc;"></div>
		
		<br>
		<br><strong>Best Regards</strong>,<br>
	<b>	P: 8429088885, 9235297990, 8303334614</b><br>
     <b>Email: support@globaltradeplaza.com</b><br>
     <b>Website: https://globaltradeplaza.com/</b><br>
<b>Address: Second Floor, 13/391, Green Park, Civil Lines, Kanpur, Uttar Pradesh, India 208001</b>
		<br><span style="color:#0f3d5a">Global Trade Plaza Team</span></div>
	
		</div>
		</div>

		

		</td>
		</tr>
		</table>
		</div>
		</div>
		</td>
		</tr>
		</table>
		
		</body>
		</html>';
	
		$fromPerson = $_POST['name'];
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
		$headers .= "From: Global Trade Plaza<support@webixytech.com>\r\n";
		$headers .= "Reply-To: deeksha@globaltradeplaza.com\r\n";
		$headers .= "X-Mailer: PHP/8.3.8\r\n";
// 		@mail($mailTo, $mailSubject, $emailmsg, $headers);
		 if (mail($mailTo, $mailSubject, $emailmsg, $headers) ) {
        echo '
        <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Success</title>
    <link
      rel="stylesheet"
      href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
    />
  </head>
  <body><div class="container mt-5" style="width:340px">
    <div class="alert alert-success text-center">
      <p>
        <i class="fa fa-check left"></i>Thank you for reaching us. We will get back to you shortly.
      </p>
      <p>
        <a class="btn btn-primary" href="https://campaigns.globaltradeplaza.com/"
          >Home</a
        >
      </p>
    </div>
  </div>
  </body>
  </html>';
    } else {
        echo '<script>alert("Failed to send mail. Please try again later.");</script>';
    }
		
	}
// 	header("Location: thank_you.php");	
	?>