dongyu9894 2014-09-18 14:11
浏览 29

我的PHP表单适用于我的godaddy托管网站,但不能在yahoo托管网站上运行,我该如何更正?

This form is for a website hosted on yahoo. I know it accepts php because I ran and test.php and it went through. The form goes nowhere after hitting submit on the yahoo website. I uploaded to another site and got an error message that says " Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/ecdo02/public_html/emag/validate.class.php on line 4". So I tried it on my own website hosted by godaddy and no errors, the form went through successfully and it showed up in my email. Does anyone have an idea what's going on? Its very strange.

This is my 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
" . "Reply-To: $email
";
    $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

 ?>

This is my 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\">
";
foreach($this->errors as $value) {
  $errorsList .= "<li>". $value . "</li>
";
}
$errorsList .= "</ul>
";
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!
";
    } else {
        $message = "There was an error sending your message!
";
    }
return $message;
 }// end hasErrors

}// end class

?>

Here is the form

    <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>
  • 写回答

1条回答 默认 最新

  • dongzu0742 2014-09-18 14:18
    关注

    Have check phpinfo() on both Yahoo and GoDaddy servers? I'll expect your Yahoo server runs with PHP 4.x while your GoDaddy server runs with PHP 5.x.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?