好的,所以我已经按照教程改变了一些变量并创建了它们。我在下面有一个HTML和PHP代码,PHP的错误是什么导致它不起作用?任何想法。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = " MY EMAIL ";
$email_subject = "FORM SUBMISSION";
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['address']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$address = $_POST['address']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$message = $_POST['message']; // required
$error_message = "";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message);
?>
<?php
header('Location: MY LINK IS HERE BUT NOT WORKING');
?>
<?php
}
?>
&#13;
表格
<div class="row contact-form">
<div class="container">
<h3>Get In Touch</h3>
<div class="col-sm-6">
<div class="row">
<form name="email" action="php/mail.php" method="POST">
<div class="col-sm-6">
<p class="input-label">Name <span class="star-red">*</span>
</p>
<input type="text" name="name" id="name" class="form-input-wide" required>
</div>
<div class="col-sm-6">
<p class="input-label">Address</p>
<input type="text" name="address" id="address" class="form-input-wide">
</div>
</div>
<div class="row">
<form name="send-mail" action="php/mail.php" method="POST">
<div class="col-sm-6">
<p class="input-label">Telephone <span class="star-red">*</span>
</p>
<input type="tel" name="telephone" id="telephone" class="form-input-wide" required>
</div>
<div class="col-sm-6">
<p class="input-label">Email <span class="star-red">*</span>
</p>
<input type="email" name="email" id="email" class="form-input-wide" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p class="input-label">Message <span class="star-red">*</span>
</p>
<textarea name="message" id="message" style="width:100% !important;" rows="6" required></textarea>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<input type="submit" class="submit-button">
</div>
</div>
<div class="row">
<div class="col-sm-6">
 
</div>
</div>
</form>
</div>
</div>
</div>
</div>
如果有什么需要改变的话?我认为错误消息可能会破坏PHP。
答案 0 :(得分:0)
PHP脚本中似乎有两个错误:
!isset($_POST['address`']) ||
needs to be
!isset($_POST['address']) ||
和
if(strlen($messages) < 2) {
needs to be
if(strlen($message) < 2) {
也许您可以查看一些&#34;表单验证器的使用情况&#34;为了更好的可用性。再次显示相同的表单然后附加错误消息会更好一点,而不是用错误消息停止脚本。
编辑:
对于标题重定向:删除空格。标题(&#39; ...&#39;)函数需要在任何浏览器输出之前运行。现在有一些空格输出到浏览器。所以删除&#34;? &GT;&#34;和&#34;&lt; ? PHP&#34;
?>
<?php
header('Location: MY LINK IS HERE BUT NOT WORKING');