-1

嗨,我正在开发一个购物车。我需要知道如何将 php 代码作为电子邮件发送给客户。当客户单击“立即订购”按钮时,必须显示一个页面,显示他购买的所有产品和一封电子邮件应该自动发送到客户的邮件ID,详细说明他购买的产品。我的问题是我不知道编写发送电子邮件的代码。有人可以帮我吗?这是我的代码。

<?php
    session_start();
    include('head.php');
?>
<?php
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $pmode=$_POST['pmode'];

    $query="INSERT INTO  customer(customer_first_name,customer_last_name,customer_email,customer_phone,payment_type)VALUES('".$fname."','".$lname."','".$email."','$phone','".$pmode."')";
    if(mysql_query($query)){
?>
<html>
    <center><font color="#493D26"><b><?php echo "Welcome $fname";?></b><font></center><br><br>
    <center><font color="#151B54"><b><?php echo "You have successfully registered";?></b></font></center>
    <?php
        echo "<br>";
        echo "<br>";
    ?>
    <form name="orderform" action="pdtorder.php" method="post">
        <table align="center" width="750" height="300">
            <tr><td> First Name:</td><td><input type="text" name="fname" value="<?php echo $fname; ?>"></td></tr>
            <tr><td>  Last Name:</td><td><input type="text" name="lname" value="<?php echo $lname; ?>"></td></tr>
            <tr><td>  Email id :</td><td><input type="text" name="email" value="<?php echo $email; ?>"></td></tr>
            <tr><td>  Phone Number :</td><td><input type="text" name="phone" value="<?php echo $phone; ?>"></td></tr>
            <tr><td> Payment Mode : </td>
            <?php
                if($pmode=='money'){
            ?>
                <td><font color="#0000A0"><b>Money Transfer</b></font><input type="radio" name="pmode" value="money" checked/></td>
                <td><font color="#0000A0"><b>Bank Transfer</b></font><input type="radio" name="pmode" value="bank"/></td>
                <td><font color="#0000A0"><b>Credit Card</b></font><input type="radio" name="pmode" value="credit"/></td></tr>
            <?php
                }
                if($pmode=='bank'){
            ?>
                <td><font color="#0000A0"><b>Money Transfer</b></font><input type="radio" name="pmode" value="money" /></td>
                <td><font color="#0000A0"><b>Bank Transfer</b></font><input type="radio" name="pmode" value="bank" checked/></td>
                <td><font color="#0000A0"><b>Credit Card</b></font><input type="radio" name="pmode" value="credit"/></td></tr>
            <?php
                }
                if($pmode=='credit'){
            ?>
                <td><font color="#0000A0"><b>Money Transfer</b></font><input type="radio" name="pmode" value="money" /></td>
                <td><font color="#0000A0"><b>Bank Transfer</b></font><input type="radio" name="pmode" value="bank" /></td>
                <td><font color="#0000A0"><b>Credit Card</b></font><input type="radio" name="pmode" value="credit" checked/></td></tr>
            <?php
                }
            ?>
        </table>
        <h4>You have ordered</h4>
        <table id="mytable" width="50%" cellpadding="1px" cellspacing="3px">
            <tr>
                <th>Item</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Subtotal</th>
            </tr>
            <?php
            $count=0;
            foreach( $_SESSION['r'] as $key=>$ar):
            ?>
            <tr id="<?php echo $ar['Id']; ?>">
                <td align="center"><?php echo $ar['Name']?></td>
                <td align="center"><?php echo $ar['Price']?></td>
                <td align="center">
                    <select class="myclass" name="qty" id='<?php echo $Identifier;?>' >
                        <?php
                            for ($i=1; $i<=100; $i++) {
                                $y="";
                                if( $i==$_SESSION['r'][$key]['Quantity']){
                                    $y="selected";
                                }
                                echo "<option ";
                                echo "value=\"$i\" ".$y.">", $i, "</option>\n";
                            }
                        ?>
                    </select>
                </td>
                <?php $x=$x+$ar['Quantity']; ?>
                <td name="price"><?php echo $ar['Total']; ?></span></td>
                <input type='hidden' name='id' id="pid_<?php echo $Identifier;?>" value='<?php echo $ar['Id']; ?>'>
                <input type='hidden' name='price' id="price_<?php echo $Identifier;?>" value='<?php echo $ar['Price'] ?>' class="input">
                <?php $tt[]=$ar['Total']; ?>
            </tr>
            <?php
                $cnt++;
            endforeach;
            ?>
        </table>
        <?php
            foreach($tt as $t){
                $count=$count+$t;
            }
        ?>
        <br><br>
        <table>
            <tr></tr>
            <tr><b><font color="B048B5">Grand Total :</font><?php echo $count; ?></b><span id="GrandTotal"></span></tr>
            <b><!--<font color="#F6358A">Your Cart:--></font></b>
            <div align="center" id="cart"><?php echo $x; ?> </div>
            <center><img src="upload/images.jpeg" width="100"></center>
        </table>
        <input type="submit" name="order" value="Order Now" />
        <input type="hidden" name="hemail" value="<?php echo $email; ?>" />
    </form>
</html>
<?php
}else{
    die(mysql_error());
}
?>
</html>

当我点击“立即订购”按钮时,我需要将 $_SESSION['r'] 作为内容发送到客户的邮件 ID。我该怎么做?由于我需要发送许多产品详细信息,我需要为每个循环使用一个,然后作为电子邮件内容发送。我该怎么做?

4

1 回答 1

0
  1. 用于singleItem存储每个项目 html
  2. singleItem准备好html后打印
  3. 追加singleItemorderItemDetailforeach 循环中
  4. orderItemDetail在您的邮件功能中使用

详细代码:

<?php
    $orderItemDetail = '';
    $count=0;
    foreach( $_SESSION['r'] as $key=>$ar):
        $x=$x+$ar['Quantity'];
        $tt[]=$ar['Total'];
        $singleItem = ''; // (1)

        $singleItem .= "<tr id='{$ar['Id']}'>\n";
        $singleItem .= "<td align='center'>{$ar['Name']}</td>\n";
        $singleItem .= "<td align='center'>{$ar['Price']}</td>\n";
        $singleItem .= "<td align='center'>\n";
        $singleItem .= "<select class='myclass' name='qty' id='{$Identifier}' >\n";
        for ($i=1; $i<=100; $i++) {
            $singleItem .="<option value='{$i}' " . (( $i==$_SESSION['r'][$key]['Quantity']) ? 'selected' : '') . ">{$i}</option>\n";
        }
        $singleItem .= "</select>\n";
        $singleItem .= "</td>\n";
        $singleItem .= "<td name='price'>{$ar['Total']}</td>\n";
        $singleItem .= "<input type='hidden' name='id' id='pid_{$Identifier}' value='{$ar['Id']}'>\n";
        $singleItem .= "<input type='hidden' name='price' id='price_{$Identifier}' value='{$ar['Price']}' class='input'>\n";
        $singleItem .= "</tr>\n";

        $orderItemDetail .= $singleItem; //(2)
        print($singleItem); //(3)
        $cnt++;
    endforeach;

    $message .= $orderItemDetail; //(4)
?>
于 2013-11-08T05:01:00.187 回答