我的代码更不用说了:
<body>
<!-- Signup Form -->
<form id="signup-form" method="post" action="">
<input type="email" name="email" id="email" placeholder="Email Address">
<input type="submit" value="Sign Up" name="submit">
</form>
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
<?php
echo "<script type='text/javascript'>alert('php loads');</script>";
if(isset($_POST['submit'])){
echo "<script type='text/javascript'>alert('enter if');</script>";
$to = "test@test.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$subject = "Form submission";
$message = "Test";
$headers = "test@test.com";
mail($to,$subject,$message,$headers);
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
我将JS警报作为一切符合预期的标志。第一个警报出现在页面加载,因此它不是PHP问题。但是,当我提交表单时,不会显示第二个警报,也不会发送电子邮件。
我错过了什么吗?
答案 0 :(得分:2)
将其添加到页面顶部:
// Should show an empty array
var_dump($_POST);
if(isset($_POST['submit'])){
var_dump('Form was submitted');
// Should show an array with your submitted values in
var_dump($_POST);
}
答案 1 :(得分:0)
$_POST
。你需要检查它是否为空。 if(!empty($_POST['submit'])
答案 2 :(得分:0)
毕竟代码工作正常。我没有在问题中包含的外部JS脚本在某种程度上干扰了表单。
感谢您的帮助
答案 3 :(得分:-1)
似乎您的代码正常
在另一个浏览器中尝试它左右
它对我有用,因为它是