2013-12-18 59 views
0

我有一個正在通過自動提示填入從數據庫PHP表單處理不能發送正確的電子郵件

<table class="table table-striped" id="itemsTable"> 
       <thead> 
       <tr> 
        <th></th> 
        <th>Item Code</th> 
        <th>Description</th> 
        <th>Qty</th> 
        <th>Price</th> 
        <th>Total</th> 
       </tr> 
       </thead> 
       <tbody> 
       <tr class="item-row"> 
        <td></td> 
        <form id="itemsForm" action="services/processOrder.php" method="post"> 
        <td><input type="text" name="itemCode[]" value="" class="input-medium" id="itemCode" 
           tabindex="1"/> 
        </td> 
        <td><input type="text" name="itemDesc[]" value="" class="input-large" id="itemDesc" 
           readonly="readonly"/></td> 
        <td><input type="text" name="itemQty[]" value="" class="input-mini" id="itemQty" tabindex="2"/> 
        </td> 
        <td> 
         <div class="input-prepend input-append"><span class="add-on">&#8364;</span> 
         <input 
           name="itemPrice[]" 
           class=" input-small" 
           id="itemPrice" 
           type="text"></div> 
        </td> 
        <td> 
         <div class="input-prepend input-append"><span class="add-on">&#8364;</span><input 
           name="itemLineTotal[]" class=" input-small" id="itemLineTotal" type="text" 
           readonly="readonly"></div> 
        </td> 
       </tr> 
       </tbody> 
      </table> 

這裏的follwing形式是自動提示php的查詢:

<?php 

require_once('db_connection.php'); 
$return_arr = array(); 

$param = $_GET["term"]; 

$query = "SELECT field_id_5, exp_weblog_titles.title, field_id_57 
      FROM exp_weblog_data, exp_weblog_titles 
      WHERE exp_weblog_titles.entry_id = exp_weblog_data.entry_id AND field_id_5 
      LIKE '%". $param ."%' 
      LIMIT 10"; 
$result = $mysqli->query($query) or die($mysqli->error.__LINE__); 

/* Retrieve and store in array the results of the query.*/ 
while ($row = $result->fetch_assoc()) { 

    $row_array['jItemCode']  = $row['field_id_5']; 
    $row_array['jItemDesc']  = $row['title']; 
    $row_array['jItemPrice']  = $row['field_id_57']; 
    //$row_array['jItemWholesale']  = $row['itemWholesale']; 
    //$row_array['jItemRetail']   = $row['itemRetail']; 
    // $row_array['jQtyOnHand']   = $row['qtyOnHand']; 

    array_push($return_arr, $row_array); 
} 


$result->free_result(); 
$mysqli->close(); 

/* Toss back results as json encoded array. */ 
echo json_encode($return_arr); 

最後這裏是用於發送表格作爲電子郵件的PHP:

<?php 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: " . $_REQUEST['repName'] . ">\r\n"; 

$to = '[email protected]'; 
$subject = "Web Contact Data"; 

$fields = array(); 
$fields{"itemCode[]"} = "Code"; 
$fields{"itemDesc[]"} = "Description"; 
$fields{"itemPrice[]"} = "Price"; 

$body = "We have received the following information:\n\n"; 

foreach($fields as $a => $b){ 
    $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); 
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com"; 


$send = mail($to, $subject, $body); 
if($send){ 
    header("Location:index.php"); 
    } else { 
     print "We encountered an error sending your mail, please try again"; 
    } 
?> 

我得到的電子郵件是「我們已經收到以下信息: 代碼: 說明: 價格: 」

請有人可以幫助我。我哪裏錯了。我知道我關閉,問題在於引用表單中數據的數組。

+0

'$ _REQUEST [$ a]'?我不是PHP專家,但這看起來不正確。如我錯了請糾正我。 – TheCarver

+0

您只顯示'代碼,描述,價格'的原因是因爲這是您在循環中唯一要做的事情。你只是循環遍歷'fields'數組,你沒有遍歷每個$ _POST請求。 – TheCarver

回答

0

很難說代碼,但主要原因是$ _REQUEST [$ a]是空的。因此,在提交表單以便更好地進行調試之後,請嘗試立即回顯整個$ _REQUEST。

另外我沒有看到提交按鈕,也結束了表單標記 - 它可能也是bug。