使用 php 处理订单以发送电子邮件


Process order form with php to send email

我有以下代码:

 <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>
                    <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 
$to = $_REQUEST['xxx'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from"; 
$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"; 
} 
?> 

此代码不起作用,请帮助

要以这种方式处理表单,您需要在标记中的某个位置有一个表单元素进行处理。

<form method="POST" action="yourSecondScript.php">
    your first markup here
    <input type="submit">
<form>

然后,为了使电子邮件与表格保持一致,您需要将电子邮件标题设置为html。

$headers  = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers .= "From: " . $_REQUEST['Name'] . ">'r'n";
mail($to, $subject, $body, $headers);

在哪里

$to = $_REQUEST['xxx'] ; 

从哪里来?我的猜测是,您可以将其设置为固定,因为您可能不需要动态电子邮件地址,因此如下所示:

$to = 'myname@mydomain.com';

但正如迈克尔在回答您的问题时提到的,在您告诉我们哪个部分不起作用/您收到哪些错误等等之前,我们无法确定。