<?php

$errorMSG = "";

// NAME
if (empty($_POST["name"])) {
    $errorMSG = "Name is required ";
} else {
    $name = $_POST["name"];
}

// EMAIL
if (empty($_POST["email"])) {
    $errorMSG .= "Email is required ";
} else {
    $email = $_POST["email"];
}

//// MSG Guest
//if (empty($_POST["guest"])) {
//    $errorMSG .= "Subject is required ";
//} else {
//    $guest = $_POST["guest"];
//}


//// MSG Event
//if (empty($_POST["event"])) {
//    $errorMSG .= "Subject is required ";
//} else {
//    $event = $_POST["event"];
//}


// MESSAGE
if (empty($_POST["message"])) {
    $errorMSG .= "Message is required ";
} else {
    $message = $_POST["message"];
}


$EmailTo = "kalametiyaseafoodrestaurant@gmail.com";
$Subject = "Restaurant Message Received";

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "guest: ";
$Body .= $guest;
$Body .= "\n";
$Body .= "event: ";
$Body .= $event;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";




$success = sendEmail("kalametiyaseafoodrestaurant@gmail.com", "test", "test");  


// redirect to success page
if ($success && $errorMSG == ""){
   echo "success";
}else{
    if($errorMSG == ""){
        echo "Something went wrong :(";
    } else {
        echo $errorMSG;
    }
}



function sendEmail($email, $subject, $text_message)
{

    $sitename = 'capitalai.tech';
    $to = $email;
    // Construct the email headers
    $headers = "From: $sitename <contact@kalametiyaseafoodrestaurant.com>\r\n";
    $headers .= "Reply-To: $sitename <contact@kalametiyaseafoodrestaurant.com>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"boundary1\"\r\n";

    // Construct the email content
    $html_message = "<html>
       <head>
           <title>Reset The Password</title>
       </head>
       <body>
           <h1>Password verification</h1>
           <p>Dear user,</p>
           <p> $text_message</p>
           <p>Best regards,</p>
           <p>The $sitename Team</p>
       </body>
       </html>";
    $message = "--boundary1\r\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $message .= $text_message;
    $message .= "\r\n\r\n--boundary1\r\n";
    $message .= "Content-Type: text/html; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $message .= $html_message;
    $message .= "\r\n\r\n--boundary1--";

    // Add unsubscribe link and mailing address to the email footer
    $message .= "\r\n\r\n<p style=\"font-size: 10px;\">You are receiving this email because you signed up for a $sitename account. To unsubscribe, click <a href=\"#\">here</a>.</p>";
    $message .= "<p style=\"font-size: 10px;\">$sitename.net<br>123 Main St<br>New York, NY 10001<br>USA</p>";


    // Send the email
    if (mail($to, $subject, $message, $headers)) {
           return "Email sent successfully.";
    } else {
        return "Email sending failed.";
    }



}
?>