2014-02-14 48 views
-1

所以我用了很長一段時間這個網站,以前從來沒有問過,但我拉出我的頭髮!請幫幫我。

我正在使用簡單腳本我發現使用表單發送結果到一個電子郵件地址。首先驗證2個字段是完整的不會讓它發送,雖然字段保存數據 - 所以我刪除該條件,它會發送一個電子郵件,但它不會顯示實際的數據。你能看看並建議嗎?

我的PHP:

<?php 
    if(!isset($_POST['submit'])) 
    { 
     //This page should not be accessed directly. Need to submit the form. 
     echo "error; you need to submit the form!"; 
    } 
    $name - $_POST['name']; 
    $description - $_POST['description']; 
    $car_year - $_POST['car_year']; 
    $big_brakes - $_POST['big_brakes']; 
    $road_car - $_POST['road_car']; 
    $type - $_POST['type']; 
    $email - $_POST['email']; 

    //Validate first 
    if(empty($name)||empty($email)) 
    { 
     echo "Name and email are mandatory!"; 
     exit; 
    } 

    if(IsInjected($visitor_email)) 
    { 
     echo "Bad email value!"; 
     exit; 
    } 

$email_from = '[email protected]';//<== update the email address 
$email_subject = "New Form submission"; 
$email_body = "You have received a new message from the user $name.\n". 
    "Here is the message:\n $name". 

$to = "[email protected]";//<== update the email address 
$headers = "From: $email_from \r\n"; 
$headers .= "Reply-To: $visitor_email \r\n"; 
//Send the email! 
mail($to,$email_subject,$email_body,$headers); 
//done. redirect to thank-you page. 
header('Location: thank-you.html'); 


// Function to validate against any email injection attempts 
function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
       '(\r+)', 
       '(\t+)', 
       '(%0A+)', 
       '(%0D+)', 
       '(%08+)', 
       '(%09+)' 
      ); 
    $inject = join('|', $injections); 
    $inject = "/$inject/i"; 
    if(preg_match($inject,$str)) 
    { 
    return true; 
    } 
    else 
    { 
    return false; 
    } 
} 

?> 

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>RAYS Wheels Quote</title> 
<link rel="stylesheet" type="text/css" href="view.css" media="all"> 
<script type="text/javascript" src="view.js"></script> 
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> 


</head> 
<body id="main_body" > 

    <img id="top" src="top.png" alt=""> 
    <div id="form_container"> 

     <h1><a>RAYS Wheels Quote</a></h1> 
     <ul > 
      <center><img src="images/Rays---Coming-soon-page_03.jpg" width="251" height="72" alt=""></td></center> 
     </ul> 
     <form method="post" name="myemailform" action="form-to-email.php"> 
       <div class="form_description"> 

      <center><p>Free Quote for RAYS Wheels, Give us the information we have asked for and we will find the Wheels for your Car.</p></center> 
     </div>      
      <ul > 

        <li id="li_1" > 
     <label for="name">name</label> 
     <div> 
      <input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li> 
       <li id="li_2" > 
     <label for="description" >Car Make and Model</label> 
     <div> 
      <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_6" > 
     <label for="car_year">Car Year</label> 
     <div> 
      <input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_3" > 
     <label for="big_brakes" >Big Brakes Fitted? Yes/No</label> 
     <div> 
      <input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_4" > 
     <label for="road_car">Road Car/Motor sport?</label> 
     <div> 
      <input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_5" > 
     <label for="type" >Type of RAYS Wheel</label> 
     <div> 
      <input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li> 
     <label class="email" >Your Email Address</label> 
     <div> 
      <input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li> 
     <li class="buttons"> 
       <input type="hidden" name="form_id" value="793428" /> 

       <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /> 
     </li> 


      </ul> 
     </form> 
     <script language="JavaScript"> 
// Code for validating the form 
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml 
// for details 
var frmvalidator = new Validator("myemailform"); 
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script> 
     <div id="footer"></a> 
     <center><center><img src="images/Rays---Form-Footer.jpg" width="624" height="264" alt="Makes"></td></div> 
    </div></center> 
    <img id="bottom" src="bottom.png" alt=""> 
    </body> 
</html> 
+0

一兩件事,改變所有' - $ _POST'到' = $ _POST'如果你從某個教程中獲得了該信息,請將其報告給ICANN(呻吟) –

+0

Plus,那麼您的命名屬性不匹配。 –

+0

唯一不匹配的是汽車模型和製造 - 我認爲描述標籤是唯一會做出不同的東西?只要這是參考? – user3311113

回答

0

PHP

改變這種從這個:

$name - $_POST['name']; 
$description - $_POST['description']; 
$car_year - $_POST['car_year']; 
$big_brakes - $_POST['big_brakes']; 
$road_car - $_POST['road_car']; 
$type - $_POST['type']; 
$email - $_POST['email']; 

這樣:

$name = $_POST['name']; 
$description = $_POST['description']; 
$car_year = $_POST['car_year']; 
$big_brakes = $_POST['big_brakes']; 
$road_car = $_POST['road_car']; 
$type = $_POST['type']; 
$email = $_POST['email']; 

HTML

從這個變化:

<label for="name">name</label> 
     <div> 
      <input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li> 
       <li id="li_2" > 
     <label for="description" >Car Make and Model</label> 
     <div> 
      <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_6" > 
     <label for="car_year">Car Year</label> 
     <div> 
      <input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_3" > 
     <label for="big_brakes" >Big Brakes Fitted? Yes/No</label> 
     <div> 
      <input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_4" > 
     <label for="road_car">Road Car/Motor sport?</label> 
     <div> 
      <input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li>  <li id="li_5" > 
     <label for="type" >Type of RAYS Wheel</label> 
     <div> 
      <input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 
     </li> 
     <label class="email" >Your Email Address</label> 
     <div> 
      <input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
     </div> 

這樣:

<label for="name">name</label> 
<div> 
    <input id="element_1" name="name" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li> 
     <li id="li_2" > 
<label for="description" >Car Make and Model</label> 
<div> 
    <input id="element_2" name="description" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li>  <li id="li_6" > 
<label for="car_year">Car Year</label> 
<div> 
    <input id="element_6" name="car_year" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li>  <li id="li_3" > 
<label for="big_brakes" >Big Brakes Fitted? Yes/No</label> 
<div> 
    <input id="element_3" name="big_brakes" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li>  <li id="li_4" > 
<label for="road_car">Road Car/Motor sport?</label> 
<div> 
    <input id="element_4" name="road_car" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li>  <li id="li_5" > 
<label for="type" >Type of RAYS Wheel</label> 
<div> 
    <input id="element_5" name="type" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li> 
<label class="email" >Your Email Address</label> 
<div> 
    <input id="element_5" name="email" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 

說明

在PHP中,當從$_POST變量設置值時,將減號更改爲等號。

在HTML中,輸入值將被傳遞給PHP腳本將基於name屬性。因此,爲了提交後傳遞值,如下面的HTML代碼:

`<input id="someid" name="test" />` 

將被傳遞給PHP作爲

$_POST['test'] 
+0

謝謝我已經嘗試過了,只是再次 - 它不給我解決方案。 – user3311113

+0

他試過這個,所以這就是爲什麼他會用'-'而不是'='(好的)來工作。經典的「可以蠕蟲」問題。 OP的代碼比這更多的事情出錯了。請仔細檢查。 –

+0

@ user3311113,我添加了解釋。 –

相關問題