1

我已经安装了 simplecart 2 jquery 购物车,并对其进行了修改以通过电子邮件将购物篮发送给我,包括添加一些额外的表格供用户首先填写。经过大量工作,我设法让购物车发送电子邮件,但只填写了用户字段,并且购物篮的内容似乎没有传递到 sendjs.php 页面。

在我的索引页面中,我在 head 部分中有以下脚本,以确保 simplecart 使用电子邮件作为结帐方法。

<script type="text/javascript">

simpleCart.email = "MY EMAIL ADDRESS";
simpleCart.checkoutTo = Email;
simpleCart.currency = GBP;

simpleCart.cartHeaders = ["Thumb_image_noHeader", "Name" , "Size_input_div_div", "Price" , "decrement_noHeader" , "Quantity", "increment_noHeader", "remove_noHeader", "Total" ];

</script>

再往下,我有生成调用函数查询的结帐按钮的代码:

<form action="sendjs.php" name="form" method="post">
<input placeholder="Name" type="text" name="name"  value="name" id="name" />
<input placeholder="Contact Number" type="text" name="phone" value="phone" id="phone" />
<input placeholder="Email" type="text" name="email" value="email" id="email" /> 
<input placeholder="Message" type="text" name="message" value="message" id="message" />     
<a href="javascript:void(0);" onclick="javascript:enquire();" class="simpleCart_checkout">Checkout</a>
</form>

在 Simplecart.js 中,我有以下函数,它应该将所需的信息传递给 sendjs.php:

    me.emailCheckout = function enquire() {    

itemsString = "";
for( var current in me.items ){ 
    var item = me.items[current];
    itemsString += item.name + " " + item.quantity + " " + item.price + "\n";
} 

name = document.form.name.value;
phone = document.form.phone.value;
email = document.form.email.value;

me.total += "" + " GBP"

var form = document.createElement("form");
form.style.display = "none";
form.method = "POST";
form.action = "sendjs.php";
form.acceptCharset = "ISO-8859-1";
form.appendChild(me.createHiddenElement("jcitems", itemsString));
form.appendChild(me.createHiddenElement("jctotal", me.total));  
form.appendChild(me.createHiddenElement("name", name));
form.appendChild(me.createHiddenElement("phone", phone));
form.appendChild(me.createHiddenElement("email", email));
document.body.appendChild(form);
form.submit();
document.form.submit();
document.body.removeChild(form);    
}

最后,我有 sendjs.php,它是生成电子邮件的原因:

<?php
/*include 'simpleCart.js';*/

$to      = 'MY EMAIL ADDRESS';
$subject = 'Order Inquiry';
$jcitems = " <p><b>ORDER:</b></p> <p> " . $_POST['jcitems']."</p>" .     "<p><b>Total:</b>     $" . $_POST['jctotal']."</p>";
$time = date ("h:i A"); 
$date = date ("l, F jS, Y");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: EMAIL' . "\r\n" .
'Reply-To: EMAIL' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$text = "<html><body><p>This form was submitted on Your Web Site on \n $date at\n $time</p><p><b>Message:</b>\n$message</p><p><b>Customers Email Address:</b>$email</p><p><b>Customers Name:</b> $name </p><p><b>Customers Phone Number:</b> $phone </p></html></body>";
$body = $text . $jcitems;
mail($to, $subject, $body, $headers);
/*Clearing the cart info after succesfull order is made*/
setcookie ("simpleCart", "", time() - 3600);

Header('Location: success.html');

echo "success!";

?>

因此,当用户单击 Checkout 时,他们会被带到成功的.html,它会向我发送一封电子邮件,但购物车的内容丢失了。

知道为什么电子邮件不包含购物车的内容吗?

任何帮助都会很棒,这正在成为一种痛苦..

(我已经取出我的电子邮件来阻止垃圾邮件机器人..)

4

0 回答 0