简体   繁体   English

PHP / HTML联络表格

[英]PHP/HTML Contact Form

I am unsure why my contact form is not working, it uses html and php but I can not for the life of me work out whatI have done wrong for it not to work. 我不确定为什么我的联系表格不起作用,它使用html和php,但我无法为自己的生命解决我做错了的事情,使其无法正常工作。 I have done weeks and weeks of research and experiments and still nothing. 我已经进行了数周和数周的研究和实验,但仍然一无所获。 I would be very grateful if somebody could point me in the correct direction. 如果有人能指出正确的方向,我将不胜感激。 Thank you, my code is below 谢谢,我的代码在下面

HTML 的HTML

<form method="POST" name="contactform" action="contact-form-handler.php"> 
<p align="center">
<label for='name'><FONT color="#FFFFFF" SIZE=2>YOUR NAME:</FONT></label> 
<font color="#FFFFFF">
<input name="name" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='telephone'><FONT SIZE=2>TELEPHONE:</FONT></label>
<input name="telephone" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='email'><FONT SIZE=2>EMAIL:</FONT></label>
<input name="email" type="text"> 
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='budget'><FONT SIZE=2>BUDGET:</FONT></label>
<input name="budget" type="text" id="finish"> 
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='location'><FONT SIZE=2>LOCATION:</FONT></label>
<input name="location" type="text" id="location"> 
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='service'><FONT SIZE=2>SERVICE:</FONT></label>
<select id="service" name="service">
<option value="000">Pick Service</option>
<option>Resealing</option>
<option>Toilet Plumbing</option>
<option>Boiler Work</option>
<option>Exterior Plumbing</option>
</select>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='message'><FONT SIZE=2>INFO:</FONT></label>
<textarea name="message"></textarea>
</font></p>

<div align="center">
<font color="#FFFFFF">
<input type="submit" value="SUBMIT">
</font></div>
</form>

PHP1 contact-form-handler PHP1联系人表单处理程序

<?php 
$errors = '';
$myemail = 'david@mildenhire.com';
if(empty($_POST['name'])  || 
   empty($_POST['telephone']) ||
   empty($_POST['email']) || 
   empty($_POST['budget']) ||
   empty($_POST['location']) ||
   empty($_POST['service']) ||
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$telephone = $_POST['telephone']; 
$email_address = $_POST['email'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$service= $_POST['service'];
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
$to = $myemail; 
$email_subject = "Free Quote: $name";
$email_body = "You have received a new free quote request. ".
" Here are the details:\n Name: $name \n Telephone: $telephone \n Email: $email_address \n Budget: $budget \n Location: $location \n Service: $service \n Message: \n $message"; 
$headers = "From: $email_address \n"; 
$headers .= "Reply-To: $email_address \n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thankyou.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title>Big Smile Free Quote Request</title>
</head>

<body>

<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>

PHP 2 contactformprocess.php PHP 2 contactformprocess.php

<?php
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "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['telephone']) || 
!isset($_POST['comments'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['first_name']; // required
$email_from = $_POST['last_name']; // required
$telephone = $_POST['email']; // required
$comments = $_POST['telephone']; // required
$antispam = $_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)==0) {
  $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
  if(strlen($first_name) < 2) {
  $error_message .= 'Your First Name does not appear to be valid.<br />';
  }
   if(strlen($last_name) < 2) {
  $error_message .= 'Your Last Name does not appear to be valid.<br />';
  } 
  if(strlen($email) < 2) {
  $error_message .= 'Your E-mail does not appear to be valid.<br />';
  } 
  if(strlen($telephone) < 2) {
  $error_message .= 'Your Telephone Number 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.\r\n";
function clean_string($string) {
 $bad = array("content-type","bcc:","to:","cc:");
 return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\r\n";
$email_message .= "Last Name: ".clean_string($last_name)."\r\n";
$email_message .= "E-Mail: ".clean_string($email)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

I know this is a fair bit to read through but it doesn't take long as it is mostly PHP Script. 我知道这是一本通俗易懂的书,但是用不了多长时间,因为它主要是PHP Script。 I hope you can help me you wonderful people 希望你能帮助我,你很棒的人

Perhaps it is just a problem of SMTP configuration. 也许这只是SMTP配置的问题。 Since you get no error, I assume the function mail() is correctly called, but if your server is not properly configured for sending emails, you can't receive anything. 由于没有错误,因此我假设已正确调用函数mail() ,但是如果未正确配置服务器发送电子邮件的功能,则您将不会收到任何信息。

My advice would be to take a look at your webserver configuration (you're probably using something like WAMP or EasyPHP). 我的建议是看一下您的Web服务器配置(您可能正在使用WAMP或EasyPHP之类的东西)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM