2017-08-09 155 views
-2

我雇主网站上的联系表单不起作用,所以他们要求我解决它。我检查了代码并发现了一些问题。 “表单方法”不正确,所以我改变了这一点。另外,send_form_email.php中的电子邮件地址是错误的,所以我也修正了这个问题,但表单仍然不起作用。任何人都可以看到我在这里错过了什么吗?公司联系表格中的破码

<form action="send_form_email.php" method="post" class="fieldbox2"> 
     <table width="344" border="0" cellspacing="0" cellpadding="0"> 
     <tr> 
      <td width="169" align="right" valign="middle"><span class="fieldbox1"> 
      <input name="first_name" type="text" id="first_name" value="First Name"/> 
      </span></td> 
      <td width="7" align="right" valign="middle">&nbsp;</td> 
      <td width="168" align="left" valign="middle"><span class="fieldbox1"> 
      <input name="last_name" type="text" id="last_name" value="Last Name"/> 
      </span></td> 
     </tr> 
     <tr> 
      <td align="right" valign="middle"><span class="fieldbox1"> 
      <input name="email" type="text" id="email" value="Email"/> 
      </span></td> 
      <td align="right" valign="middle">&nbsp;</td> 
      <td align="left" valign="middle"><span class="fieldbox1"> 
      <input name="city" type="text" id="city" value="City"/> 
      </span></td> 
     </tr> 
     <tr> 
      <td align="right" valign="middle"><span class="fieldbox1"> 
      <input name="telephone" type="text" id="telephone" value="Phone Number"/> 
      </span></td> 
      <td align="right" valign="middle">&nbsp;</td> 
      <td align="left" valign="middle"><span class="fieldbox1"> 
      <input name="company" type="text" id="company" value="Company"/> 
      </span></td> 
     </tr> 
     <tr> 
      <td colspan="3" align="center" valign="middle"><textarea name="textarea2" cols="45" id="textarea2">Write Comments</textarea></td> 
     </tr> 
     <tr> 
      <td colspan="3" align="center" valign="middle"><p> 
      <input name="sendbutton" type="button" id="sendbutton" value="Submit Query"/> 
      </p></td> 
     </tr> 
     </table> 
    </form> 

<?php 
if(isset($_POST['email'])) { 


    $email_to = "#"; 
    $email_subject = "Quote Requested"; 


    function died($error) { 

     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 


    if(!isset($_POST['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['city']) || 
     !isset($_POST['telephone']) || 
     !isset($_POST['company']) || 
     !isset($_POST['comments'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $city = $_POST['city']; // required 
    $telephone = $_POST['phone_number']; // not required 
    $company = $_POST['company']; // not required 
    $comments = $_POST['comments']; // required 

    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
    } 
    if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
    } 
    if(!preg_match($string_exp,$city)) { 
    $error_message .= 'The City you entered does not appear to be valid.<br />'; 
    } 
    if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
    } 
    if(strlen($error_message) > 0) { 
    died($error_message); 
    } 
    $email_message = "Form details below.\n\n"; 

    function clean_string($string) { 
     $bad = array("content-type","bcc:","to:","cc:","href"); 
     return str_replace($bad,"",$string); 
    } 

    $email_message .= "First Name: ".clean_string($first_name)."\n"; 
    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 
    $email_message .= "Company: ".clean_string($company)."\n"; 
    $email_message .= "Comments: ".clean_string($comments)."\n"; 



$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers); 
?> 


Thank you for contacting us. We will be in touch with you very soon. 
<?php 

} 

?> 
+0

不以什么方式工作? – Matt

+1

那么,有什么不正确的工作? “但是这个表单仍然不起作用”,这是非常含糊的 – Carcigenicate

+0

哦,对不起,点击提交按钮时没有任何反应,我没有写这个代码,我只是想弄清楚它有什么问题。 –

回答

0

从我可以在你的代码中看到您需要的意见作为输入,但我无法找到名为“意见”的任何输入。这可能是你面临的问题。你的评论输入'textarea2 '

+0

非常感谢。这解决了它! –