0

これに関連する別の話題を見ましたが、私はまだ PHP の基礎を学んでいるので、まだ少し混乱していました。したがって、Order.php に投稿するフォームがあります。これにより、電子メールが送信され、正常に機能します。フォームを Review.php に投稿してから送信したいと思います。以下は私の Order.PHP です (かなり長いため、配列からいくつかの入力フィールドを削除しました)。私は review.php について考えていましたが、すべての order.php コードを使用することができますが、いくつかの html$send = mail($to, $subject, $body, $headers);でリクエスト$to, $subject, $body, $headersする代わりに、それらを order.php に送信する sumbit ボタンを用意することができます。レビューページで処理されます。そうですか?

order.phpは次のとおりです

<?php 

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

 $to = "packy@mycompany.com";
 $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: noreply@mycompany.com"; 
 $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"; } 
 }
}
 ?>
4

2 に答える 2

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: noreply@mycompany.com\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",  "packy@mycompany.com");
    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\\.@-_]/', '', $_POST['CustomerEmail']),
        'fitter' => preg_replace('/[^A-Za-z0-9\\.@-_]/', '', $_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
于 2013-05-01T21:15:03.827 に答える
0

はい。

ユーザーにレビュー ページを表示し、そのページに非表示にして、注文ページに提供された情報を埋め込むことができます。

ページの確認 ボタンのマークアップを確認します。

<form name="review" action="order.php" method="POST">
  <input type="hidden" name="FitterName" value="Bob Smith">
  <input type="hidden" name="FitterEmail" value="a@b.com">
  <input type="submit" value="Submit">
</form>

レビューページの送信ボタンをクリックすると、注文情報が表示されます。ページに転送されorder.phpます。

于 2013-05-01T20:49:44.037 に答える