<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        include 'smtp/PHPMailerAutoload.php';
    
        $name = htmlspecialchars($_POST['name']);
        $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
        $phone = htmlspecialchars($_POST['phone']);
        $subject = htmlspecialchars($_POST['subject']);
        $message = htmlspecialchars($_POST['message']);
        
        // Build the email body with HTML
        $body = "<div>";
        $body .= "<p><b>Name: </b> $name</p>";
        $body .= "<p><b>Phone: </b> $phone</p>";
        $body .= "<p><b>Email: </b> $email</p>";
        $body .= "<p><b>Subject: </b> $subject</p>";
        $body .= "<p><b>Message: </b> $message</p>";
        $body .= "</div>";
    
        $mail = new PHPMailer();
        // $mail->SMTPDebug = 2; 
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 587;
        $mail->IsHTML(true);
        $mail->CharSet = 'UTF-8';
    
        $mail->Username = "abs.gyankr@gmail.com";
        $mail->Password = 'mobjpahqfzycnpry';
    
        $mail->SetFrom($email, $name);
        $mail->FromName = "Govind Technochem";
        $mail->AddAddress('govindtechnochem@gmail.com'); 
    
        $mail->Subject = 'Govind Technochem - Contact Form';
        $mail->Body = $body;
    
        if ($mail->Send()) {
            header("Location: contact-us.php?status=success");
            exit();
        } else {
            header("Location: contact-us.php?status=error");
            exit();
        }
    }