PHP表单不会通过服务器发送

时间:2016-11-15 18:34:13

标签: php forms

我正在使用Hostgator进行服务器端处理,我正在使用他们的表单来尝试实现这一点,但它不会发送。我进入错误页面,我的网址显示。 “... com / email_form.php?do = send”我是否遗漏了一些将拉动操作以使用服务器端处理的内容,或者是否有一个我没有看到的错误?

<?php
switch (@$_GET['do'])
{

 case "send":

  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $femail = $_POST['femail'];
  $f2email = $_POST['f2email'];
  $saddy = $_POST['saddy'];
  $scity = $_POST['scity'];
  $szip = $_POST['szip'];
  $fphone1 = $_POST['fphone1'];

  $mname = $_POST['mname'];
  $sapt = $_POST['sapt'];
  $sstate = $_POST['sstate'];
  $scountry = $_POST['scountry'];
  $fphone2 = $_POST['fphone2'];
  $fphone3 = $_POST['fphone3'];
  $fsendmail = $_POST['fsendmail'];
  $secretinfo = $_POST['info'];

if (!preg_match("/\S+/",$fname))
{
  unset($_GET['do']);
  $message = "First Name required. Please try again.";
  break;
}
if (!preg_match("/\S+/",$lname))
{
  unset($_GET['do']);
  $message = "Last Name required. Please try again.";
  break;
}
if (!preg_match("/^\S+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,6}$/",$femail))
{
  unset($_GET['do']);
  $message = "Primary Email Address is incorrect. Please try again.";
  break;
}
if ($f2email){
  if (!preg_match("/^\S+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,6}$/",$f2email))
  {
    unset($_GET['do']);
    $message = "Secondary Email Address is incorrect. Please try again.";
    break;
  }
}
if (!preg_match("/\S+/",$saddy))
{
  unset($_GET['do']);
  $message = "Street Address required. Please try again.";
  break;
}
if (!preg_match("/\S+/",$scity))
{
  unset($_GET['do']);
  $message = "City required. Please try again.";
  break;
}
if (!preg_match("/^[0-9A-Za-z -]+$/",$szip))
{
  unset($_GET['do']);
  $message = "Zip/Post Code required. Please try again.";
  break;
}
if (!preg_match("/^[0-9 #\-\*\.\(\)]+$/",$fphone1))
{
  unset($_GET['do']);
  $message = "Phone Number 1 required. No letters, please.";
  break;
}

if ($secretinfo == "")
{
   $myemail = "myemail@email.com";
   $emess = "First Name: ".$fname."\n";
   $emess.= "Middle Name: ".$mname."\n";
   $emess.= "Last Name: ".$lname."\n";
   $emess.= "Email 1: ".$femail."\n";
   $emess.= "Email 2: ".$f2email."\n";
   $emess.= "Street Address: ".$saddy."\nApt/Ste: ".$sapt."\n";
   $emess.= "City: ".$scity."\nState: ".$sstate."\nZip/Post Code:".$szip."\n";
   $emess.= "Country: ".$scountry."\n";
   $emess.= "Phone number 1: ".$fphone1."\n";
   $emess.= "Phone number 2: ".$fphone2."\n";
   $emess.= "Phone number 3: ".$fphone3."\n";
   $emess.= "Comments: ".$fsendmail;
   $ehead = "From: ".$femail."\r\n";
   $subj = "An Email from ".$fname." ".$mname." ".$lname."!";
   $mailsend=mail("$myemail","$subj","$emess","$ehead");
   $message = "Email was sent.";
}

   unset($_GET['do']);
   header("Location: thankyou.html");
 break;

default: break;
}
?><html>
<body>
<form action="email_form.php?do=send" method="POST">
<p>* Required fields</p>
<?php
   if ($message) echo '<p style="color:red;">'.$message.'</p>';
?>
<table border="0" width="500">
 <tr><td align="right">* First Name: </td>
     <td><input type="text" name="fname" size="30" value="<?php echo @$fname ?>"></td></tr>
 <tr><td align="right">Middle Name: </td>
     <td><input type="text" name="mname" size="30" value="<?php echo @$mname ?>"></td></tr>
 <tr><td align="right">* Last Name: </td>
     <td><input type="text" name="lname" size="30" value="<?php echo @$lname ?>"></td></tr>
   </table>
<p>
<table border="0" width="500">
<tr><td align="right">* Primary Email: </td>
     <td><input type="text" name="femail" size="30" value="<?php echo @$femail ?>"></td></tr>
 <tr><td align="right">Secondary Email: </td>
     <td><input type="text" name="f2email" size="30" value="<?php echo @$f2email ?>"></td></tr>
</table>
<p>
<table border="0" width="600">
<tr><td align="right">* Street Address: </td>
<td><input type="text" name="saddy" size="40" value="<?php echo @$saddy ?>"></td></tr>
   <tr><td align="right">Apartment/Suite Number: </td>
     <td><input type="text" name="sapt" size="10" value="<?php echo @$sapt ?>"></td></tr>
 <tr><td align="right">* City: </td>
     <td><input type="text" name="scity" size="30" value="<?php echo @$scity ?>"></td></tr>
     <td align="right">State: </td>
     <td><input type="text" name="sstate" size="10" value="<?php echo @$sstate ?>"></td></tr>
 <tr><td align="right">* Zip/Post Code: </td>
     <td><input type="text" name="szip" size="10" value="<?php echo @$szip ?>"></td></tr>
 <tr><td align="right">Country: </td>
     <td><input type="text" name="scountry" size="30" value="<?php echo @$scountry ?>"></td></tr>
   </table>
<p>
<table border="0" width="500">
 <tr><td align="right">* Phone Number 1: </td>
     <td><input type="text" name="fphone1" size="20" value="<?php echo @$fphone1 ?>"></td></tr>
  <tr><td align="right">Phone Number 2: </td>
     <td><input type="text" name="fphone2" size="20" value="<?php echo @$fphone2 ?>"></td></tr>
  <tr><td align="right">Phone Number 3: </td>
     <td><input type="text" name="fphone3" size="20" value="<?php echo @$fphone3 ?>"> <input style="display:none;" name="info" type="text" value=""> </td></tr>
   </table>
<p>
<table border="0" width="500"><tr><td>
 Comments:<br />
 <TEXTAREA name="fsendmail" ROWS="6" COLS="60"><?php if($fsendmail) echo $fsendmail; ?></TEXTAREA>
 </td></tr>
 <tr><td align="right"><input type="submit" value="Send Now">
 </td></tr>
 </table>
 </form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您的表单方法为POST,但您使用的是$_GET。将表单方法切换为GET或将变量切换为$_POST