我正在编写一个简单的启动页面,并使用节点的http-server
对其进行测试。每当我单击“提交”按钮时,都是想给我发送电子邮件,而是在HTTP服务器控制台上收到错误消息:
[Fri Jul 13 2018 10:02:37 GMT-0500 (Central Daylight Time)] "POST /" Error (404): "Not found"
如果这很简单,但我不是Web开发人员,请原谅,这是我的代码:
<?php
if(isset($_POST['submit'])){
$to = "email@example.com";
$from = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$message = $first_name . " " . $last_name . " sent an email" . "\n\n";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: thankyou.html');
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="=content-type" content="text/html"; charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Toby Inc.</title>
</head>
<body>
<table width="200" border="0">
<tbody><table Align="center">
<tr>
<th scope="col"><img src="logoNEW.jpg" width="580" height="710" alt=""/></th>
</tr>
</tbody>
</table>
<!-- You're probably going to want to play with this
since the form is aligned to the left side -->
<form action="" method="post">
Firstname: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
<input type="submit" name="submit" value="Submit to be inspired">
</form>
</body>
</html>
thankyou.html文件只是说“谢谢”
我在做什么错了?
答案 0 :(得分:0)
在表单的action
属性中,您应指定将数据发布到的文件的URL。
如果您希望它提交到同一页面/ URL,请完全删除该属性。
答案 1 :(得分:0)