PHP 表单处理未发送正确的电子邮件

标签 php mysql forms

我有以下表单,正在通过数据库中的自动建议填充

<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>

这是自动建议的 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 = 'dominic.mcafee@pmcnttyyre.com'; 
 $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: noreply@example.com"; 
 $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"; 
    } 
?> 

我在电子邮件中收到的只是“我们收到了以下信息: 代码: 描述: 价格: ”

请有人帮帮我。我哪里错了。我知道我已经很接近了,问题出在引用表单中的数据数组的某个地方。

最佳答案

很难从代码中看出,但主要原因是 $_REQUEST[$a] 为空。因此,请尝试在提交表单后立即回显整个 $_REQUEST,以便更好地进行调试。

此外,我没有看到提交按钮和表单标记的结尾 - 这也可能是错误。

关于PHP 表单处理未发送正确的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20657349/

相关文章:

php - 如何以 ='background-image' 标签风格对来自 mysql 的图像进行编码

ruby-on-rails - 一种型号有多种更新表格

PHP 过期日期

php - Ubuntu Lamp - 代理 - 防火墙 - Joomla curl 和 fsockopen 无法工作

mysql - 如何从 MySQL 的列中删除特定字符的所有实例

php - MySQL 的简单 PHP 表单出错

javascript - 防止 HTML 形式的 JS/CSS

PHP ImageMagick 从 http 获取图像

php - IIS 7 上的 WordPress php-cgi 占用 CPU

mysql - 当事件发生时,如何使用 ionic 3 和 laravel 5.6 从服务器向移动应用程序的用户发送通知