我写了一个只有电子邮件字段的 html 表单。我想转移用户发送的电子邮件 输入到我的网络服务器上的文本文件中。
当我点击提交按钮时出现白屏。没有任何内容写入我的文本文件。 我还想在用户单击提交按钮时将用户重定向到另一个页面。 这可能吗?我是新手。
<?php
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
fclose($file);
print_r(error_get_last());
?>
<form action= "emaillist.php" method="post" name="email ">
<input type="text" name="email">
<br>
<br>
<input type="submit" name="email" value="submit"><br>
最佳答案
除了 Andy G 所说的更改提交按钮的名称之外:
<?php
//Get the email from POST
$email = $_REQUEST['email'];
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
print_r(error_get_last());
//redirect
header("Location: http://www.example.com/");
不要在<?php
之间留空行和文件的开头,否则重定向将不起作用。
关于php - 使用 PHP 从 HTML 表单写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17868399/