<?php
if(isset($_POST['submit'])){

$name = $_POST['name'];
$phone = $_POST['phone'];
$product = $_POST['product'];

require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
require 'PHPMailer/Exception.php';

$mail = new PHPMailer\PHPMailer\PHPMailer(true);

try{
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'jggventors@gmail.com';   // Gmail
$mail->Password = 'your_app_password';     // Gmail App Password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Sender (Must be Gmail if using Gmail SMTP)
$mail->setFrom('jggventors@gmail.com','Kalpavruskha');

// Reply To (Your domain email)
$mail->addReplyTo('info@kalpavruskha.com','Kalpavruskha Info');

// Receiver
$mail->addAddress('jggventors@gmail.com');

$mail->Subject = "New Product Order";
$mail->Body = "Name: $name\nPhone: $phone\nProduct: $product";

$mail->send();

// WhatsApp Redirect
header("Location: https://wa.me/919999999999?text=New Order - $product");
exit;

}catch(Exception $e){
echo "Email failed: {$mail->ErrorInfo}";
}
}
?>