我雇主网站上的联系表格不起作用,所以他们让我解决。我检查了代码,发现了一些问题。 "形式方法"是不正确所以我改变了。此外,send_form_email.php中的电子邮件地址是错误的,所以我也修复了它,但表单仍然无法正常工作。谁能看到我在这里失踪的东西?
<form action="send_form_email.php" method="post" class="fieldbox2">
<table width="344" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="169" align="right" valign="middle"><span class="fieldbox1">
<input name="first_name" type="text" id="first_name" value="First Name"/>
</span></td>
<td width="7" align="right" valign="middle"> </td>
<td width="168" align="left" valign="middle"><span class="fieldbox1">
<input name="last_name" type="text" id="last_name" value="Last Name"/>
</span></td>
</tr>
<tr>
<td align="right" valign="middle"><span class="fieldbox1">
<input name="email" type="text" id="email" value="Email"/>
</span></td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"><span class="fieldbox1">
<input name="city" type="text" id="city" value="City"/>
</span></td>
</tr>
<tr>
<td align="right" valign="middle"><span class="fieldbox1">
<input name="telephone" type="text" id="telephone" value="Phone Number"/>
</span></td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"><span class="fieldbox1">
<input name="company" type="text" id="company" value="Company"/>
</span></td>
</tr>
<tr>
<td colspan="3" align="center" valign="middle"><textarea name="textarea2" cols="45" id="textarea2">Write Comments</textarea></td>
</tr>
<tr>
<td colspan="3" align="center" valign="middle"><p>
<input name="sendbutton" type="button" id="sendbutton" value="Submit Query"/>
</p></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['email'])) {
$email_to = "#";
$email_subject = "Quote Requested";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['city']) ||
!isset($_POST['telephone']) ||
!isset($_POST['company']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$city = $_POST['city']; // required
$telephone = $_POST['phone_number']; // not required
$company = $_POST['company']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$city)) {
$error_message .= 'The City you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
答案 0 :(得分:0)
从我在你的代码中看到的你需要注释作为输入,但我找不到任何名为&#39; comments&#39;的输入。这可能是您面临的问题。您将评论输入命名为&#39; textarea2 &#39;