<?php include 'header.php';?>
<?php 

// error_reporting(E_ALL);
// ini_set('display_errors', 1);
include("classess/class.phpmailer.php");
include("classess/class.smtp.php");
  $secretKey="6Lf8KdErAAAAACYDAwqi7Q8AUi8uBB6X8TkH1INk";
if(isset($_POST['submit'])){
   
     if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ 
 
             $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); 
             
            // Decode JSON data of API response 
            $responseData = json_decode($verifyResponse); 
             
            // If the reCAPTCHA API response is valid 
            if($responseData->success){ 
   
                $phone  = $_POST['phone'];
                $name    = $_POST['name'];
                $email   = $_POST['email'];
                $subject  = 'New Enquiry';
                $message = $_POST['message'];
              
                
                
                $mssg= ' <html>
                <body>
                <h1>New Enquiry</h1>
                <table cellspacing="0" style="width: 300px; height: 200px;">
                <tr>
                <th>Name:</th><td>'.$name.'</td>
                </tr>
                <tr>
                <th>Phone:</th><td>'.$phone.'</td>
                </tr>
                <tr>
                <th>Email:</th><td>'.$email.'</td>
                </tr>
                <tr>
                <th>Message:</th><td>'.$message.'</td>
                </tr>
                </table>
                </body>
                </html>';
                
                $mail = new PHPMailer(); // create a new object
                $mail->IsSMTP(); // enable SMTP//
                $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
                $mail->SMTPAuth = true; // authentication enabled

                $mail->SMTPSecure = "ssl";
                $mail->Host = "smtp.gmail.com";
                $mail->Port = 465;
                $mail->Username = "mineralsbmi@gmail.com";
                $mail->Password = "lcwfosjtramnarhq";
                $mail->SetFrom("mineralsbmi@gmail.com");
                $mail->Subject = $subject;
                $mail->Body = $mssg;
                $mail->IsHTML(true);
                $mail->AddAddress('info@bmiminerals.com.vn');

                
                if(!$mail->Send()){
                echo "Mailer Error: " . $mail->ErrorInfo;
                }
                else{  
              
              
                $sql = "INSERT INTO enquiry(name,email,message,phone)
                VALUES ('$name','$email','$message','$phone')";
                mysqli_query($conn,$sql);
                   mysqli_close($conn);
                echo '<script>alert("Your Request Send Successfully");</script>';
                echo '<script>window.location.replace("contact-us.php");</script>';
                }
            }
            
   
        }else{ 
        
            echo '<script>alert("Please check the reCAPTCHA checkbox.");</script>';
            echo '<script>window.location.replace("contact-us.php");</script>';
        }       
} ?>
<div class="breadcrumb bg-grey text-center py-3 mb-0">
    <div class="container">
        <h2 class="mb-0">Contact Us</h2>
    </div>
</div>
<section class="innerpage py-5">
    <div class="container">
        <div class="row g-4">
            <?php 
            $sql= "SELECT * FROM contact";
            if($result=mysqli_query($conn,$sql)){    
            while($row = mysqli_fetch_array($result)){ ?>       
            <div class="col-md-4">
                <h3>Get In Touch</h3>
                <p>We’d love to hear from you! Whether you’re ready to start your design journey or just have a few questions, our team is here to help.</p>
                <p class="text-capitalize"><i class="fa fa-map-marker-alt"></i> <b>Office Address</b><br><?php echo $row['address'];?></p>
                <p><i class="fa fa-envelope"></i> <b>Email</b><br><?php echo $row['email'];?><br>For general inquiries, quotes, or appointments</p>
                <p><i class="fa fa-phone"></i> <b>Phone</b><br><?php echo $row['mobile'];?><br><?php echo $row['timing'];?></p>
			</div>
            <?php } } ?>
                    
            <div class="col-md-8">
			    <form method="post">
                  <div class="form-group mb-3">
                    <input type="text" class="form-control" placeholder="Enter Name" name="name" required>
                  </div>
                  <div class="form-group mb-3">
                    <input type="email" class="form-control" placeholder="Enter Email" name="email" required>
                  </div>  
                  <div class="form-group mb-3">
                    <input type="text" class="form-control" placeholder="Enter Phone No." name="phone" required onkeypress="return onlyNumberKey(event)" minlength="10" maxlength="10" >
                  </div>
                  <div class="form-group mb-3">
                    <textarea type="text" class="form-control" rows="7" placeholder="Enter Message"  name="message"></textarea>
                  </div>
                  <div class="g-recaptcha" data-sitekey="6Lf8KdErAAAAAGO3DNjqZgGwdG40GeDjGwPFCg72" style="transform:scale(0.77);-webkit-transform:scale(0.77);transform-origin:0 0;-webkit-transform-origin:0 0;"></div>
                            
                  <button type="submit" name="submit" class="btn1">Submit</button>
                </form>
            </div>
        </div>
    </div>
</section>

  <?php include 'footer.php';?>