警告:无法修改标头信息 - 已在C:\ xampp \ htdocs \ contact-form-submission.php中发送的标头(在C:\ xampp \ htdocs \ contact-form-submission.php:1处开始输出)在第5行
<html>
<form method="POST" action="contact-form-submission.php" class="well smallspace">
Name<br><input type="text" name="name" placeholder="Type you name here" style="width:85%" required><br>
Phone Number<br><input type="Number" name="phnumber" placeholder="Type your phone number" style="width:85%" required/><br>
Email id<br><input type="email" name="emailid" placeholder="Type you email id" style="width:85%" required/><br>
Enter your message<br>
<textarea rows="5" cols="30" name="message" placeholder="Type you message here" style="width:85%" ></textarea><br>
<input type="submit" value="Send" class="btn btn-primary"></input><br><br>
</form>
</html
<?php
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {
header("Location: localhost/contact.php"); exit;
}
// get the posted data
$name = $_POST["name"];
$email_address = $_POST["emailid"];
$message = $_POST["message"];
$phone = $_POST["phnumber"];
// check that a name was entered
if (empty ($name))
$error = "You must enter your name.";
// check that an email address was entered
elseif (empty ($email_address))
$error = "You must enter your email address.";
// check for a valid email address
elseif (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email_address))
$error = "You must enter a valid email address.";
// check that a message was entered
elseif (empty ($message))
$error = "You must enter a message.";
// check whether a valid phone number
elseif(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone) )
$error = 'Please enter your valid phone number';
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
header("Location: contact.php?e=".urlencode($error)); exit;
}
// write the email content
$email_content = "Name: $name\n";
$email_content .= "Email Address: $email_address\n";
$email_content .= "Phone number: $phone";
$email_content .= "Message:\n\n$message";
// send the email
mail ("abc@xyz.com","New Contact Message",$email_content);
// send the user back to the form
header("Location: contact.php?s=".urlencode("Thank you for your message.")); exit;
?>
AB
答案 0 :(得分:0)
听起来你的文件顶部可能有一个额外的空间(之前可能没有空格)
<?php
标签(既不是空格也不是换行符)。
编辑:根据您更新的代码,尝试将PHP代码放在HTML上,因为在浏览器的任何输出(HTML计数)之后您都没有PHP标题()。