<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中制作而不是电子邮件之后我不知道它是如何解决的
答案 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是不同的。所以选择相应的。