2013-05-01 39 views
0

我看到另一个相关的主题,但仍然有点confuesed,因为我仍然是PHP的基本。所以我有一个表单发布到我的Order.php。这发送电子邮件,工作得很好。我希望表单发布到Review.php然后发送。下面是我的Order.PHP(我从数组中删除了一些输入字段,因为它相当长)。我在考虑review.php我只能使用所有的order.php代码,而不是$send = mail($to, $subject, $body, $headers);我可以在一些html中请求$to, $subject, $body, $headers然后有一个sumbit按钮,将它们发送到order.php,因为所有这些都将被简化数据在评论页面中处理。这听起来是对的吗?php之前审查电子邮件

order.php如下

<?php 

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 

$to = "[email protected]"; 
$name = $_REQUEST['FitterName'] ; 
$from = $_REQUEST['FitterEmail'] ; 
$headers = "From: $from"; 
$subject = "Online Order"; 
$name2 = $_REQUEST['CustomerEmail'] ; 

$grind = join(", ", $_REQUEST["grind"]); 
$woods = join(", ", $_REQUEST["woods"]); 
$hybrids = join(", ", $_REQUEST["hybrids"]); 
$iron = join(", ", $_REQUEST["iron"]); 
$wedges = join(", ", $_REQUEST["wedges"]); 

$fields = array(); 
$fields{"AccountName"} = "Accounts's Name: "; 
$fields{"FitterName"} = "Fitter's Name: "; 
$fields{"CustomerCat"} = "__________________________CUSTOMER INFO__________________________"; 
$fields{"CustomerName"} = "Customer's Name: "; 
$fields{"CustomerPhone"} = "Customer's Phone: "; 
$fields{"CustomerAddress"} = "Customer's Address: "; 



$body = "We have received the following Online Order from www.mycompany.com:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%2s %s\n",$b,$_REQUEST[$a]); } 
$body2 = "Please Review the following Online Order from www.mycompany.com:\n\n"; foreach($fields as $a => $b){  $body2 .= sprintf("%2s %s\n",$b,$_REQUEST[$a]); } 




$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for your order"; 
$autoreply = "Thank you for your order. Customer service will call in the next 24 hours to review your order."; 

$autoreply2 = "Company Customer"; 

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
$send3 = mail($name2, $subject2, $autoreply2, $headers2); 
if($send) 
{header("Location: http://fitter.henry-griffitts.com/fitter/success.php");} 
else 
{print "We encountered an error sending your mail, please review your information"; } 
} 
} 
?> 

回答

0

是。

您可以向用户显示评论页面,并隐藏在该页面中,您可以在订单页面上嵌入他们提供的信息。

评论页确认按钮标记;

<form name="review" action="order.php" method="POST"> 
    <input type="hidden" name="FitterName" value="Bob Smith"> 
    <input type="hidden" name="FitterEmail" value="[email protected]"> 
    <input type="submit" value="Submit"> 
</form> 

当他们点击提交审查页面他们的订单信息上的按钮。将被转发到order.php页面。

+0

所以在这我会从原来的HTML表单隐藏包裹在'

'我的所有领域提交到下一工序。如何通过review.php上的$ body数据显示数据,以便他们在提交数据之前检查数据?谢谢 – Packy 2013-05-01 21:16:41

+0

您可以通过将其数据放在表单外的'review.php'页面的其他位置来显示其数据。例如。 。'回声“

Name:{$_REQUEST['FitterName']}
' – 2013-05-01 21:31:39

+0

感谢我结束了同时使用你的球员的解决方案 – Packy 2013-05-02 22:37:06

0

这是您的review.php文件的一个非常基本的例子。它将每个字段添加为表单中的隐藏输入变量。

<p>Does everything look correct?</p> 
<form method="post" action="order.php"> 
    <ul> 
    <?php 
     if (is_array($_REQUEST)) { 
      foreach ($_REQUEST as $key => $val) { 
       echo "<li><strong>" . $key . "</strong>: " . $val . "</li>"; 

       // This code should support the checkboxes and multiple selects 
       if (is_array($val)) { 
        foreach ($val as $val2) { 
         echo "<input type='hidden' name='" . $key . "[]' value='" . $val2 . "' />"; 
        } 
       } 
       else { 
        echo "<input type='hidden' name='" . $key . "' value='" . $val . "' />"; 
       } 
      } 
     } 
    ?> 
    </ul> 
    <input type="submit" value="Submit Info" /> 
</form> 

现在在你的order.php上,让它清理起来并简化一下,只是因为。

<?php 
    //define some fields 
    define("HEADERS", "MIME-Version: 1.0\r\nContent-type:text/html;charset=iso-8859-1\r\nFrom: [email protected]\r\n"); 
    define("BODY_1", "We have received the following Online Order from www.mycompany.com:"); 
    define("BODY_2", "Please Review the following Online Order from www.mycompany.com:"); 
    define("SUBJECT_1", "Online Order"); 
    define("SUBJECT_2", "Thank you for your order"); 
    define("MY_EMAIL", "[email protected]"); 
    define("REPLY",  "Thank you for your order. Customer service will call in the next 24 hours to review your order.") 

    //sanitize your inputs. I like to remove every character that is not allowed 
    $data = array(
     'name' => preg_replace('/[^A-Za-z\\s]/', '', $_POST['FitterName']), 
     'email' => preg_replace('/[^A-Za-z0-9\\[email protected]_]/', '', $_POST['CustomerEmail']), 
     'fitter' => preg_replace('/[^A-Za-z0-9\\[email protected]_]/', '', $_POST['FitterEmail']), 
     'grind' => preg_replace('/[^A-Za-z\\s,]/', '', implode(',', $_POST['grind'])), 
     //the rest of your fields 
    ); 

    //do your field checks here, exit out or return them to the form 

    //send your emails 
    $send = mail(MY_EMAIL, SUBJECT_1, BODY_1 . print_r($data, true), HEADERS); 
    $send2 = mail($data['fitter'], SUBJECT_2, BODY_2 . print_r($data, true), HEADERS); 
    $send3 = mail($data['email'], SUBJECT_2, REPLY, HEADERS); 

    //more code and redirect 
+0

谢谢,工作惊人的我只是2个问题@jon_o:。 [UL] -is有一个如何发布输入有填写信息,而不是列出所有的输入? - 我调用这样的一些数据 V-研磨 \t \t \t \t \t 游Grind' [/ UL ] \t \t \t \t \t 所以我可以调用多个复选框。当我测试这个数据在review.php上看起来像是“wedges:Array”。我怎么能解决这个问题? 再次感谢! – Packy 2013-05-02 03:34:43

+0

@Packy,我更新了上面的代码,以展示如何重写那些作为隐藏输入的数组的字段。 **或者**,你可以检查这个字段是否像我在代码示例中那样是一个数组,然后只是像“echo””;然后你只需更新你的订单。PHP接受字段而不是数组。那有意义吗? – 2013-05-02 17:01:26

+0

@jon_o,谢谢你。但它仍然显示为“数组”的值,如“grinds:array”。我尝试了顶级代码,并像上面所说的那样将其更改为字符串。 – Packy 2013-05-02 19:39:50