dourong4031 2019-03-04 18:38
浏览 40

Jquery购物车数据发送到电子邮件

I want to send the data from the order to the email + contact form send.

I do not know how to send cart data to an email with a contact form

function load_cart_data()
    {
     
        $.ajax({
            url:"fetch_cart.php",
            method:"POST",
            dataType:"json",
            success:function(data)
            {
                $('#cart_details').html(data.cart_details);
                $('.total_price').text(data.total_price);
                $('.badge').text(data.total_item);
            }
        });
    }
Cart ....
<?php

//fetch_cart.php

session_start();

$total_price = 0;
$total_item = 0;

$output = '
<div class="table-responsive" id="order_table">
    <table class="table table-bordered table-striped">
        <tr>  
            <th width="40%">Product Name</th>  
            <th width="10%">Quantity</th>  
            <th width="20%">Price</th>  
            <th width="15%">Total</th>  
            <th width="5%">Action</th>  
        </tr>
';
if(!empty($_SESSION["shopping_cart"]))
{
    foreach($_SESSION["shopping_cart"] as $keys => $values)
    {
        $output .= '
        <tr>
            <td>'.$values["product_name"].'</td>
            <td>'.$values["product_quantity"].'</td>
            <td align="right">$ '.$values["product_price"].'</td>
            <td align="right">$ '.number_format($values["product_quantity"] * $values["product_price"], 2).'</td>
            <td><button name="delete" class="btn btn-danger btn-xs delete" id="'. $values["product_id"].'">Remove</button></td>
        </tr>
        ';
        $total_price = $total_price + ($values["product_quantity"] * $values["product_price"]);
        $total_item = $total_item + 1;
    }
    $output .= '
    <tr>  
        <td colspan="3" align="right">Total</td>  
        <td align="right">$ '.number_format($total_price, 2).'</td>  
        <td></td>  
    </tr>
    ';
}
else
{
    $output .= '
    <tr>
        <td colspan="5" align="center">
            Your Cart is Empty!
        </td>
    </tr>
    ';
}
$output .= '</table></div>';


$data = array(
    'cart_details'      =>   $output,
    'total_price'       =>   '$' . number_format($total_price, 2),
    'total_item'        =>   $total_item
);  

echo json_encode($data);


?>
email send 
<?php
$namebusiness = $_POST['namebusiness'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$adress = $_POST['adress'];
$city = $_POST['city'];
$psc = $_POST['psc'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$data = $_POST['data'];

$message = $_POST['cart_details'];
$email_subject = "Order";

$email_body = "Name Of Business: $namebusiness.
 "."First name: $firstname.
 "."Last name: $lastname.
"."E-mail: $visitor_email.
"."Adress: $adress.
 "."City: $city.
 "."Post Code / ZIP: $psc.
 "."State: $state.
 "."Phone number: $phone.
";
                   
$to = "patrikl123@seznam.cz";
$to = $_POST['email'];

$headers = 'From: domaci@potrebyhanka.cz' . "
" .
    'Reply-To: domaci@potrebyhanka.cz' . "
" .
    'Content-type: text/html; charset=UTF-8' . "
". 
    'X-Mailer: PHP/' . phpversion();

mail($to, $email_subject,$message,$email_body,$headers);
header("Content-type: text/html; charset=UTF-8");
header("Location: index.php");
//https://stackoverflow.com/questions/30802674/retrieve-data-from-cart-and-send-using-mail


?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法