Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将php呈现HTML结果作为电子邮件内容_Php_Email - Fatal编程技术网

如何将php呈现HTML结果作为电子邮件内容

如何将php呈现HTML结果作为电子邮件内容,php,email,Php,Email,您好,我正在开发一个购物车。我需要知道如何将php代码作为电子邮件发送给客户。当客户单击“立即订购”按钮时,必须显示一个页面,显示他购买的所有产品,并且应自动向客户的邮件id发送一封电子邮件,详细说明他购买的产品。我的问题是我不知道如何编写发送电子邮件的代码。有人能帮我吗? 这是我的密码 <?php session_start(); include('head.php'); ?> <?php $fname=$_POST['fname']; $ln

您好,我正在开发一个购物车。我需要知道如何将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>

  • 使用
    singleItem
    存储每个项目
  • 准备好html后,打印
    singleItem
  • singleItem
    追加到foreach循环中的
    orderItemDetail
  • 在邮件功能中使用
    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)
    ?>
    

    邮件($to,$subject,$message)
    可能存在重复,但我将放置什么$message?我不知道如何将$u会话['r']附加为我的$message。请帮助我