<?php
include 'header.php'; 
?>

<?php 
$msg = "";
$err = "";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
	if (isset($_POST['send'])) {
		$subject = text_input($_POST['subject']);

		$message = text_input($_POST['message']);
        $res = text_input($_POST['res']);
		if (!empty($subject) && !empty($res) && !empty($message) ) {
            sendMail($res, $subject, $message);
			$msg = "Message successfully sent";
		}
	}
?>

<div class="page-content">
    <div class="container-fluid">
<?php 
	if ($msg != "") {
		echo customAlert("success", $msg);
	}
	if ($err != "") {
		echo customAlert("error", $err);
	}

 ?>

    	<div class="row">
            <div class="col-lg-12">
                <div class="card">
                	<div class="card-body">
                		<div class="card-header">
			                <h4 class="card-title mb-0">Send Mail to a user</h4>
			            </div>
			            <form method="post" action="mailuser.php">
                        <div class="live-preview">
                            <div class="row gy-4">
                                <div class="col-xxl-6 col-md-12">
                                    <div>
                                        <label for="basiInput" class="form-label">Subject</label>
                                        <input type="text" class="form-control" name="subject" id="basiInput">
                                    </div>
                                </div>
                                
                                <div class="col-xxl-6 col-md-12">
                                    <div>
                                        <label for="basiInput" class="form-label">Send mail to</label>
                                        <input type="text" class="form-control" name="res" id="basiInput">
                                    </div>
                                </div>
                                <div class="col-xxl-6 col-md-12">
                                    <div>
                                        <label for="basiInput" class="form-label">Message</label>
                                        <textarea class="form-control" rows="5" name="message" placeholder="Type Message..."></textarea>
                                    </div>
                                </div>
                                <div class="col-xxl-6 col-md-12">
                                    <div>
                                        <button type="submit" name="send" class="btn btn-primary">Send</button>
                                    </div>
                                </div>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>


	</div>
</div>
<?php include 'footer.php'; ?>