im pretty new on it, my question is how to make it work
<?php
$errors = [];
if (isset($_POST['submitted']) && $_POST['submitted'] == 1)
{
    $email = trim($_POST["email"]);
    $message = trim(stripslashes($_POST['message']));
    $to = "adam9311@abv.bg";
    if (!filter_var($email, FILTER_VALIDATE_EMAIL))
    {
        $errors['email'] = "<p>Please type a valid email address.</p>";
        }
    if (empty($message))
    {
        $errors['message'] = "<p>Please type your message.</p>";
    }
    if (empty($errors)) // if  empty $errors array
    {
        require 'PHPMailerAutoload.php';
        $mail = new PHPMailer;
        mail($to,$message,$email);
        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }
    }
}
?>
<?php if (!empty($errors)) : ?>
    <?php foreach ($errors as $key => $error) : ?>
        <p><?php echo $error; ?></p>
    <?php endforeach; ?>
<?php endif; ?>
    <form name="contact" action="index.php" method="post">
        <input type="hidden" name="submitted" value="1"/>
        <label for="email">Your Email:</label>
        <input type="text" name="email" class="required" id="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>">
        <br />
        <label for="message">Your Message:</label>
        <textarea  name="message" cols="10" rows="10" class="required" id="message"><?php echo isset($_POST['message']) ? $_POST['message'] : ''; ?></textarea>
    <fieldset>
        <input type="submit" name="submit" id="submit" value="Send" class="required"/>
    </fieldset>
</form>
 
    