<?php 

if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $number = $_POST['number'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    // echo "<h1>$name</h1>";
    
    $new_name = addslashes($name);
    $new_number = addslashes($number);
    $new_email = addslashes($email);
    $new_message = addslashes($message);
    

    $servername = "localhost";
    $username = "erltetmy_thepropartner";
    $password = "thepropartner@123";
    $dbname = "erltetmy_thepropartner";

    date_default_timezone_set('Asia/Kolkata');
    $my_date = date("Y-m-d H:i:s");
    // $my_date = strtotime($current_date);

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn) {
      echo "Database Connection failed: " . mysqli_connect_error();
    }
    else{
      $sql = "INSERT INTO invest_now (name, number, email, message, date_time) VALUES ('$new_name', '$new_number', '$new_email', '$new_message','$my_date')";
      if (mysqli_query($conn, $sql)) {
        echo "<script>alert('Thank you, Your form has been successfully submitted we will contact you shortly.');</script>";
      } 
      else {
        echo "<script>alert('Error: Something Went Wrong Please Try again Later ". mysqli_error($conn)."')</script>";
      }
    }
    mysqli_close($conn);


    $from = "digital@brandswitch.in";
    
    $to .= ",digital@brandswitch.in";
    $to .= ",jyoti.brandswitch@gmail.com";
    $to .= ",Atul.metrohomes@gmail.com";
    
    $subject = "Pro Partner Website New Inquiry";
    $message = "Hello,\n\nPFB Details of New Inquiry.\n\nName: ".$new_name."\nNumber: ".$new_number."\nEmail: ".$new_email."\nMessage: ".$new_message."\nDate Time: ".$my_date;

    $headers = "From:".$from;
    
    mail($to,$subject,$message,$headers);
    
}
?>