<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php session_start(); $emailErr = $emailErr1 = ""; $email = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["email"])) { $emailErr = "Email邮箱不能为空!"; $emailErr1 = "<script>alert('邮箱不能为空')</script>"; } else { $email = test_input($_POST["email"]); $_SESSION['email']=$_POST['email']; $emailErr1 = "<script>alert('邮箱正确');parent.location.href='phpmail.php';</script>"; if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){ $emailErr = "无效的 email 格式"; $emailErr1 = "<script>alert('请填写正确的邮箱,如82958399@qq.com!')</script>"; } } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> E-mail: <input type="text" name="email"> <span class="error">* <?php echo $emailErr; echo $emailErr1; ?> </span> <br><br> <input type="submit" name="submit" value="立刻发送邮件"> </form> </body> </html>