流程订单表格用php发送电子邮件

时间:2013-12-18 09:54:22

标签: php 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>
                    <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处理输入的最佳方式是通过电子邮件发送订单nicley形成表格?这是一份订单,我需要在完成后简单地发送到电子邮件

这是我的处理代码:

<?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"; 
} 
?> 

此代码无效请求帮助

2 个答案:

答案 0 :(得分:0)

在哪里

$to = $_REQUEST['xxx'] ; 
来自哪里?我的猜测是你可以将它设置为固定,因为你可能不需要动态电子邮件来解决,所以像这样:

$to = 'myname@mydomain.com';

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

答案 1 :(得分:0)

要以这种方式处理表单,您需要在标记中的某处使用表单元素进行处理。

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