发送/发现错误后,联系表单的警报

时间:2016-11-30 13:17:34

标签: php html forms contact alerts

我自己对PHP不好,所以我想知道如果有人在这里可以帮助我解决我的问题。我的主页是以下代码

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Leave a Message</title>
    <link href="bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome.min.css" rel="stylesheet">
    <link href="custom.css" rel="stylesheet">
</head>

<body id="particles">


<body id="particles">

    <div class="main">
                <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header text-center">
                    <h4 class="modal-title">Leave a message</h4>
                </div>
                <div class="modal-body">
                    <form method="post" action="contact_me.php">
                            <div class="form-group">
                                <label>Your name</label>
                                <br>
                                <input type="text" class-"form-control" name="name" required="" style="width: 100%;">
                            </div>
                                                        <div class="form-group">
                                <label>Your email</label>
                                <br>
                                <input type="text" class-"form-control" name="email" required="" style="width: 100%;">
                            </div>
                            <div class="form-group">
                                <label>Your message</label>
                                <br>
                                <textarea type="text" class-"form-control" name="message" required="" style="width: 100%; max-width: 100%; min-height: 100px"></textarea>
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-info" style="width: 100%;">Submit</button>
                            </div>
                    </form>
                </div>
                <div class="modal-footer" style="text-align: center;">
                    <small>Copyright © 2016. All Rights Reserved.</small>
                </div>
            </div>
        </div>
    </div>

    <script src="jquery.min.js"></script>
    <script src="particles.jquery.min.js"></script>
    <script src="custom.min.js"></script>

</body>

</html>

我的行动是contact_me.php,该代码是

<?php
// Check for empty fields
if(empty($_POST['name'])        ||
   empty($_POST['email'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    header( 'Location: http://www.wotm8.net/error-pages/contact' ) ;
    return false;
   } header('Location: ' . $_SERVER['HTTP_REFERER']);

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$message = strip_tags(htmlspecialchars($_POST['message']));

// Create the email and send the message
$to = 'me@lolnick.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;    
?>

我想知道是否有人可以教我如何添加提醒。例如,如果找到错误它将显示一个红色文本框并说出错误。如果联系表格是正确的,它将显示绿色文本框并说明已发送联系表格。

0 个答案:

没有答案