PHP写文件从multiply到txt中选择

时间:2016-06-08 15:20:22

标签: php forms

抱歉,但我没有学习PHP,所以任何人都可以帮助我。如果访问者填写表格并按提交,我想要在txt文件中写出的表格的输出和“谢谢”这样的信息是答案

<form role="form" method="post" id="contact-form">
                        <input type="text" placeholder="Name" name="Name" id="Name" required>
                        <input type="email" placeholder="Email" name="Email" id="Email" required>
                        <input type="text" placeholder="Phone" name="Phone" id="Phone">
                         <select name="test">
                            <option selected disabled="disabled"> Where do you live?</option>
                            <option value="test12"> Al Amirat</option>
                            <option value="test13"> Other</option>
                        </select>
                        <br>
                        <button type="submit" id="submit"> Submit</button>
                        <div id="success"></div>
                    </form>

最后一个PHP代码是用来发送电子邮件

<?php 
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['Phone'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];

$to = 'test@email.com';
$subject = 'the subject';
$message = 'FROM: '.$name.'  Email: '.$email.'  Phone: '.$phone.'  Subject: '.$subject.'  Message: '.$message;
$headers = 'From: youremail@domain.com' . "\r\n";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "Your email was sent!"; // success message
}else{
echo "Invalid Email!";
}

 ?>

但是在客户端需要添加从地方选择并在txt中制作而不是电子邮件之后我不知道它是如何解决的

1 个答案:

答案 0 :(得分:0)

这是一个例子,

$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);

详细检查示例Here

你可能会遇到很多事情。

文件夹权限:
PHP必须具有您要保存文件的文件夹的写权限。哪777权限。所以要非常小心安全性。

路径分隔符
路径分隔符对于linux和windows是不同的。所以选择相应的。