我的PHP表单在我的godaddy托管网站上有效,但在雅虎托管网站上不起作用,我该如何更正


My PHP form works on my godaddy hosted website, but will not work on a yahoo hosted website, how can I correct this?

此表单适用于雅虎上托管的网站。我知道它接受php,因为我运行并测试了php,它通过了。在雅虎网站上点击提交后,该表格就不见了。我上传到另一个网站,收到一条错误消息,上面写着"分析错误:语法错误,意外的T_STRING,在/home/edo02/public_html/emag/validate.class.php的第4行中应为T_OLD_FUNCTION或T_FUNCTION、T_VAR或'}'"。所以我在godaddy主持的自己的网站上尝试了一下,没有出现任何错误,表格成功通过,并显示在我的电子邮件中。有人知道发生了什么事吗?这很奇怪。

这是我的请求。php

<?php
define("EMAIL", "xxxxxxx@xxxxx.com");
 if(isset($_POST['submit'])) {
 include('validate.class.php');
//assign post data to variables
$firstname = trim($_POST['firstname']);
$lastname = trim($_POST['lastname']);
$company = trim($_POST['company']);
$address = trim($_POST['address']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$zip = trim($_POST['zip']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$fax = trim($_POST['fax']);
$title = trim($_POST['title']);
$interest = trim($_POST['interest']);
$comment = trim($_POST['comment']);
//start validating our form
$v = new validate();
$v->validateStr($firstname, "firstname", 3, 75);
$v->validateStr($lastname, "lastname", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone");
$v->validateStr($comment, "comment", 10, 500); 

//use php's mail function to send the email
    @mail($email_to, $subject ,$message ,$header ); 
    if(!$v->hasErrors()) {
    $header = "From: $email'n" . "Reply-To: $email'n";
    $subject = "Lead from Website";
    $email_to = EMAIL;
    $message = "A message was submitted.
    From: $title $firstname $lastname
    Company: $company
    Address: $address
    City: $city
    State/ Province/ Region: $state
    Postal/ Zip Code: $zip
    E-mail: $email
    Phone: $phone
    Fax: $fax
    What would you like? $interest
    Comments:
    $comment
    -End of message
    "; 

//grab the current url, append ?sent=yes to it and then redirect to that url
    $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    header('Location: '.$url."?sent=yes");
    } else {
//set the number of errors message
$message_text = $v->errorNumMessage();      
//store the errors list in a variable
$errors = $v->displayErrors();
//get the individual error messages
$firstnameErr = $v->getError("firstname");
$lastnameErr = $v->getError("lastname");
$phoneErr = $v->getError("phone");
$emailErr = $v->getError("email");
$commentErr = $v->getError("comment");
}//end error check
}
// end isset
 ?>

这是我的validate.class.php

<?php
class validate {
  public $errors = array();
  public function validateStr($postVal, $postName, $min = 1, $max = 500) {
if(strlen($postVal) < intval($min)) {
  $this->setError($postName, ucfirst($postName)." field is required.");
} else if(strlen($postVal) > intval($max)) {
  $this->setError($postName, ucfirst($postName)." must be less than {$max} characters long.");
  }
 }// end validateStr

  public function validateEmail($emailVal, $emailName) {
if(strlen($emailVal) <= 0) {
  $this->setError($emailName, "Please enter an e-mail address");
} else if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-   zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $emailVal)) {
  $this->setError($emailName, "Please enter a valid e-mail address");
    }
   }// end validateEmail

  /* Validate phone no to allow numbers only */    
    public function validatePhone($phoneVal, $phoneName) {
    if (strlen($phoneVal) <= 0) {
        $this->setError($phoneName, "Please enter your phone number"); 
    } else if (preg_match('/[^0-9]/', $phoneVal)) { 
        $this->setError($phoneName, "Please enter a valid phone number");
    }
} // end validatephone

 /* sets an error message for a form element*/   
  private function setError($element, $comment) {
$this->errors[$element] = $comment;
}

  /* returns the error of a single form element*/ 
  public function getError($elementName) {
if($this->errors[$elementName]) {
  return $this->errors[$elementName];
  } else {
  return false;
  }
 }
 /* displays the errors as an html un-ordered list*/ 
 public function displayErrors() {
$errorsList = "<ul class='"errors'">'n";
foreach($this->errors as $value) {
  $errorsList .= "<li>". $value . "</li>'n";
}
$errorsList .= "</ul>'n";
return $errorsList;
}

/* returns whether the form has errors*/
public function hasErrors() {
if(count($this->errors) > 0) {
  return true;
} else {
  return false;
}
}

 /* returns a string stating how many errors there were*/
  public function errorNumMessage() {
if(count($this->errors) > 1) {
        $message = "There were " . count($this->errors) . " errors sending your message!'n";
    } else {
        $message = "There was an error sending your message!'n";
    }
return $message;
 }// end hasErrors
}// end class
?>

这是的表格

    <form id="contact_form" method="post" action="request.php">
                    <fieldset>
                        <legend>Thank You</legend>
                      <div style="padding-left:100px">    
                        <?php if(isset($_GET['sent'])): ?><table width="590" border="0">
    <tr>
<td width="590" colspan="2"></td>
     </tr>
     <tr>
<td colspan="2">
  <div style="padding:30px; text-align:center"><span style="font-size:24px; font-weight:bold;     ">Thank You!<br /><br /><span style="font-family:Arial, Helvetica, sans-serif; font-size:15px; background:; padding:20px; width:300px;text-align:center">Your submission has been submitted.</span></div>
  </td>
   </tr>
   </table></div><?php endif; ?>
  </fieldset>


                   <fieldset>
                        <legend>Request</legend>
                      <div style="padding-left:100px">    
                        <table width="590" border="0">
    <tr>
<td colspan="2"></td>
  </tr>
   <tr>
<td colspan="2"></td>
</tr>
   <tr>
<td width="195"><label>What would you like? </label></td>
<td width="395"><select name="interest">
  <option value=""> -- Please select -- </option>
  <option>Add me to your mailing list.</option>
  <option>Send me an information kit.</option>
  <option>Call me to set up a meeting.</option>
  </select></td>
    </tr>
  </table></div>
 </fieldset>
                    <fieldset>
                 <legend>Personal Info</legend>
                   <div style="padding-left:100px;"> 
                     <table width="590" border="0" cellpadding="10" cellspacing="5">
                          <tr>
                            <td width="195" align="right"><label><b>Title</b></label></td>
                            <td width="395"><select name="title" style="width:183px">
  <option value=""> - Select Your Title - </option>
  <option>Mr.</option>
  <option>Mrs.</option>
  <option>Miss</option>
  <option>Ms.</option>
  <option>Dr.</option>
  <option>Prof.</option>
  <option>Rev.</option>
  <option>Other</option>
</select>
                            </td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right"><label><b>First Name</b><span style="color: red">        *</span></label></td>
                            <td><input type="text" name="firstname" value="<?php echo htmlentities($firstname); ?>" />                                <br /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $firstnameErr; ?></span></td>
                          </tr>
                          <tr>
                            <td align="right"><label><b>Last Name<span style="color: red">        *</span></b></label></td>
                            <td><input type="text" name="lastname" value="<?php echo htmlentities($lastname); ?>" />                                  <br /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $lastnameErr; ?></span></td>
                          </tr>
                          <tr>
                             <td><label><b>Company</b></label></td>
<td><input type="text" name="company"  value="<?php echo htmlentities($company); ?>" /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                       </tr>
                          <tr>
                             <td><label><b>Street Address</b><span style="color: red"> *</span>      </label></td>
<td><input type="text" name="address"  value="<?php echo htmlentities($address); ?>" /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $addressErr; ?></span></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                       </tr>
                          <tr>
                             <td><label><b>City</b><span style="color: red"> *</span></label>       </td>
<td><input type="text" name="city" value="<?php echo htmlentities($city); ?>" /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $cityErr; ?></span></td>
                          </tr>
                          <tr>
                            <td><label><b>State</b><span style="color: red"> *</span></label></td>
<td><input type="text" name="state"  value="<?php echo htmlentities($state); ?>" />      <br /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $stateErr; ?></span></td>
                          </tr>
                          <tr>
                            <td><label><b>Postal/Zip Code</b><span style="color: red"> *</span>            </label></td>
<td><input type="text" name="zip"  value="<?php echo htmlentities($zip); ?>" />      <br /></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><span class="errors"><?php echo $zipErr; ?></span></td>
                          </tr>
                     </table></div>
                    </fieldset>
                    <fieldset>
                        <legend>Contact Info</legend>
                       <div style="padding-left:100px;"> 
                        <table width="590" border="0" cellpadding="10" cellspacing="5">
    <tr>
      <td><label><b>E-mail</b><span style="color: red"> *</span></label></td>
        <td><input type="text" name="email"  value="<?php echo htmlentities($email); ?>" /></td>
 </tr>
 <tr>
<td>&nbsp;</td>
<td><span class="errors"><?php echo $emailErr; ?></span></td>
   </tr>
  <tr>
<td><label><b>Phone</b><span style="color: red"> *</span></label></td>
<td><input type="text" name="phone" value="<?php echo htmlentities($phone); ?>" /></td>
 </tr>
 <tr>
<td>&nbsp;</td>
     <td><span class="errors"><?php echo $phoneErr; ?></span></td>
     </tr>
     <tr>
      <td width="195"><label><b>Fax</b></label></td>
          <td width="395"><input type="text" name="fax" value="<?php echo htmlentities($fax); ?>" />
    </td>
      </tr>
     </table></div>
                    </fieldset>
                    <fieldset>
                           <legend>Additional Notes</legend>
                       <div style="padding-left:100px;"> 
                        <table width="590" border="0" cellpadding="10">
         <tr valign="top">
       <td width="195"><label><b>Your Comment:</b></label></td>
         <td width="395"><textarea name="comment" rows="10" cols="50" style="width: 300px;"/>
      <?php echo htmlentities($comment); ?></textarea><br />
  <span class="errors"><?php echo $commentErr ?></span><br /></td>
      </tr>
    <tr>
   <td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td> 
    <td>
  </td>
   </tr>
  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
     </tr>
 <tr>
<td>&nbsp;</td>
<td><input type="submit" value="submit" name="submit" class="button" /></td>
   </tr>
   <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
    </tr>
                        </table>
        </div>
                </form>

是否检查过雅虎和GoDaddy服务器上的phpinfo()?我希望您的Yahoo服务器使用PHP 4.x运行,而GoDaddy服务器使用PHP 5.x运行。