我的PHP表单可以在godaddy托管的网站上使用,但在yahoo托管的网站上无法使用,我如何更正此问题?

我的PHP表单可以在godaddy托管的网站上使用,但在yahoo托管的网站上无法使用,我如何更正此问题?,php,Php,此表格适用于雅虎网站。我知道它接受php,因为我运行了test.php并通过了测试。在点击雅虎网站上的提交后,该表单将毫无用处。我上传到另一个站点,收到一条错误消息,上面写着“语法错误,意外的T_字符串,在第4行的/home/ecdo02/public_html/emag/validate.class.php中应为T_OLD_函数或T_函数或“}”。因此,我在godaddy主持的我自己的网站上尝试了它,没有出现错误,表单成功通过,并显示在我的电子邮件中。有人知道发生了什么吗?这很奇怪 这是我的r

此表格适用于雅虎网站。我知道它接受php,因为我运行了test.php并通过了测试。在点击雅虎网站上的提交后,该表单将毫无用处。我上传到另一个站点,收到一条错误消息,上面写着“语法错误,意外的T_字符串,在第4行的/home/ecdo02/public_html/emag/validate.class.php中应为T_OLD_函数或T_函数或“}”。因此,我在godaddy主持的我自己的网站上尝试了它,没有出现错误,表单成功通过,并显示在我的电子邮件中。有人知道发生了什么吗?这很奇怪

这是我的request.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

 ?>

在Yahoo和GoDaddy服务器上都有check phpinfo()?我希望您的Yahoo服务器使用PHP 4.x运行,而GoDaddy服务器使用PHP 5.x运行。

不要使用正则表达式验证电子邮件地址,请使用
filter\u var($value,filter\u validate\u email)
。。。相信我,我已经看到这个问题贴了至少3次了。你为什么一遍又一遍地问同样的问题?雅虎服务器运行的是旧版本的PHP,无法处理新语法。听起来像是PHP4。找出如何切换Yahoo服务器以使用较新的PHP版本。我不是想把问题发过去,我不是想让我的表单工作,因为我知道它可以工作,而是更了解为什么它不能在一台主机上工作,而在另一台主机上工作得很好。我想可能是php版本的问题。PHP4?你在开玩笑吗?雅虎在2009年之前一直雇佣Lerdorf,毫无疑问,他们有一个非常可靠的、定制的PHP5I版本,而且它有最新版本的PHP5.3,所以看起来这不是一个版本问题?PHP4与PHP5的区别在于
var$errors
public$errors
<?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>