繁体   English   中英

订单数据发送到电子邮件

[英]Order data send to email

我想将购物车发送到电子邮件,但我不能......请帮忙,谢谢。

我不知道该怎么做,我已经尝试了很多选择,但都没有成功

PHP代码:

<?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'];
  $email_subject = "Order";

  $message = "
  <html>

  <head>
    <title>Your order</title>
  </head>

  <body>
    <table>
      <tr>
        <th>Name Of Business:</th>
        <td>$namebusiness</td>
      </tr>
      <tr>
        <th>First name</th>
        <td>$firstname</td>
      </tr>
      <tr>
        <th>Last name:</th>
        <td>$lastname</td>
      </tr>
      <tr>
        <th>E-mail:</th>
        <td>$visitor_email</td>
      </tr>
      <tr>
        <th>Adress:</th>
        <td>$adress</td>
      </tr>
      <tr>
        <th>City:</th>
        <td>$city</td>
      </tr>
      <tr>
        <th>Post Code / ZIP:</th>
        <td>$psc</td>
      </tr>
      <tr>
        <th>State:</th>
        <td>$state</td>
      </tr>
      <tr>
        <th>Phone number:</th>
        <td>$phone</td>
      </tr>

      <tr>
        <th>Product Name</th>
        <th>Quantity</th>
        <th>Price</th>
        <th>Total</th>

      </tr>
    </table>
  </body>

  </html>
  ";

  $to = "$visitor_email, patrikl123@seznam.cz";
  $headers = 'From: Czech@HouseITD.com' . "\r\n" .
      'Content-type: text/html; charset=UTF-8' . "\r\n". 
      'X-Mailer: PHP/' . phpversion();

  mail($to,$email_subject,$message,$headers);
  header("Content-type: text/html; charset=UTF-8");
  header("Location: thanks.html");
?>

索引.php:

<?php
//index.php
?>
<!DOCTYPE html>
<html>

<head>

  <script src="js/jquery.min.js"></script>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="style1.css">
  <link rel="stylesheet" href="css/bootstrap.min.css" />
  <title>Czech House ITD</title>
  <script src="js/bootstrap.min.js"></script>


  <div id="navbar-cart" class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li>
        <a id="cart-popover" class="btn" data-placement="bottom" title="Shopping Cart">
          <span class="glyphicon glyphicon-shopping-cart"></span>
          <span class="badge"></span>
          <span class="total_price">£ 0.00</span>

        </a>
      </li>
    </ul>
  </div>

  </div>
  </nav>


  <form id="concact-form" method="post" action="concact-form.php">
    <div id="popover_content_wrapper" style="display: none">
      <span id="cart_details"></span>
      <div align="right">

        <a href="concact.php" class="btn btn-primary" id="check_out_cart">
          <span class="but"></span>Send
        </a>
        <a href="#" class="btn btn-default" id="clear_cart">
          <span class="glyphicon glyphicon-trash"></span> Clear
        </a>
      </div>
    </div>
  </form>
  <div id="display_item">

  </div>

  </div>
  <br />
  <div class="footer1">
    <h7 class="footer2">Copyright © 2018 Patrik Schiller </h7>

  </div>
  </body>

</html>

JavaScript 代码:

$(document).ready(function() {

  load_product();

  load_cart_data();

  function load_product() {
    $.ajax({
      url: "fetch_itemtoys.php",
      type: "POST",
      success: function(data) {
        $('#display_item').html(data);
      }
    });
  }

  function load_cart_data() {

    $.ajax({
      url: "fetch_carttoys.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-popover').popover({
    html: true,
    container: 'body',
    content: function() {
      return $('#popover_content_wrapper').html();
    }
  });

  $(document).on('click', '.add_to_cart', function() {
    var product_id = $(this).attr("id");
    var product_name = $('#name' + product_id + '').val();
    var product_price = $('#price' + product_id + '').val();
    var product_quantity = $('#quantity' + product_id).val();
    var action = "add";
    if (product_quantity > 0) {
      $.ajax({
        url: "actiontoys.php",
        method: "POST",
        data: {
          product_id: product_id,
          product_name: product_name,
          product_price: product_price,
          product_quantity: product_quantity,
          action: action
        },
        success: function(data) {
          load_cart_data();
          alert("Item has been Added into Cart");
        }
      });
    } else {
      alert("lease Enter Number of Quantity");
    }
  });

  $(document).on('click', '.delete', function() {
    var product_id = $(this).attr("id");
    var action = 'remove';
    if (confirm("Are you sure you want to remove this product?")) {
      $.ajax({
        url: "actiontoys.php",
        method: "POST",
        data: {
          product_id: product_id,
          action: action
        },
        success: function() {
          load_cart_data();
          $('#cart-popover').popover('hide');
          alert("Item has been removed from Cart");
        }
      })
    } else {
      return false;
    }
  });

  $(document).on('click', '#clear_cart', function() {
    var action = 'empty';
    $.ajax({
      url: "actiontoys.php",
      method: "POST",
      data: {
        action: action
      },
      success: function() {
        load_cart_data();
        $('#cart-popover').popover('hide');
        alert("Your Cart has been clear");
      }
    });
  });
});

感谢您的帮助

只需添加 MIME 版本:

$headers = 'From: Czech@HouseITD.com' . "\r\n" .
    "MIME-Version: 1.0" . "\r\n" . 
    'Content-type: text/html; charset=UTF-8' . "\r\n". 
    'X-Mailer: PHP/' . phpversion();

顺便说一下,你在这里有无用的串联,你可以写:

$headers = 'From: Czech@HouseITD.com \r\n' .
    'MIME-Version: 1.0 \r\n' . 
    'Content-type: text/html; charset=UTF-8 \r\n'. 
    'X-Mailer: PHP/' . phpversion();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM