php来形成脚本?语法错误意外

时间:2010-02-04 11:55:26

标签: php forms syntax contact

嗨,任何人都可以建议一个PHP表单的快速表单脚本? 我从telepro生成了下面的一个并修改了html和电子邮件,但我收到了这个错误的复选框

解析错误:语法错误,第14行/home/inn.co.uk/public/mailer.php中的意外'='

感谢您的帮助

此致 朱迪

     <form method="POST" action="contact.php">

<div class="form-field">
  <input type="text" name="Name" onFocus="if(this.value=='Name')this.value='';" value="Name">
</div>
 <div class="form-field">
  <input type="text" name="Telephone" onFocus="if(this.value=='Telephone')this.value='';" value="Telephone">
</div>
<div class="form-field">
  <input type="text" name="Timetocall" onFocus="if(this.value=='Time to call')this.value='';" value="Time to call">
  </div>
<div class="form-field">
                <ul class="tickboxes">
                                      <li>Do you agree to our<br/><a href="terms-and-conditions.html">Terms of Business </a><input type="checkbox" name="DoyouagreetoourTermsofBusiness?" value="Yes" /></li></ul></div>




            <div class="button">
              <input type="image" src="images/submit.jpg" value="" name="submit">
            </div>
     </form>

<?php
// Website Contact Form Generator 
// http://www.tele-pro.co.uk/scripts/contact_form/ 
// This script is free to use as long as you  
// retain the credit link  

// get posted data into local variables
$EmailFrom = "enquiry@inn.co.uk";
$EmailTo = "judith@yahoo.co.uk";
$Subject = "New enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Timetocall = Trim(stripslashes($_POST['Timetocall'])); 
$DoyouagreetoourTermsofBusiness? = Trim(stripslashes($_POST['DoyouagreetoourTermsofBusiness?'])); 

// validation
$validationOK=true;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Timetocall)=="") $validationOK=false;
if (Trim($DoyouagreetoourTermsofBusiness?)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Timetocall: ";
$Body .= $Timetocall;
$Body .= "\n";
$Body .= "DoyouagreetoourTermsofBusiness?: ";
$Body .= $DoyouagreetoourTermsofBusiness?;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

1 个答案:

答案 0 :(得分:2)

您在变量名称中使用了问号。这不起作用。

有关命名约定,请参阅PHP Manual on variables

替换

$DoyouagreetoourTermsofBusiness?

通过

$DoyouagreetoourTermsofBusiness

它会正常工作。