0

我想使用最新的 SimpleCart JS (v3) 来使用电子邮件结帐。不幸的是,没有实际的 sendform php 文件的来源。

我使用以下方法启动了 SimpleCart:

simpleCart({
  checkout: { 
    type: "SendForm" , 
    url: "sendcart.php" ,
    method: "POST" , 
    success: "success.php" , 
    cancel: "cancel.php"
  }
});

并使用这个 sendcart.php

<?php
  $to      = 'mail@someshop.com';
  $subject = 'Simple Cart Order';
  $body = $_POST;
  $headers = 'From: webmaster@example.com' . "\r\n" .
          'Reply-To: webmaster@example.com' . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
  mail($to, $subject, $body, $headers);
  Header('Location: thankyou.php');
?>

我坚持的是,我应该使用 $_POST 来调用购物车的内容来填充 $body 吗?

作为一个非编码员,这对我来说有点难以猜测 :) 不过,对你们中的一些人来说可能很明显 :)

这是simplecart.js 文件

谢谢!

编辑:

我终于明白 $_POST 是一个数组。现在我需要一个循环来提取数组的值。

4

2 回答 2

5

苦苦挣扎,但终于成功了:

  <?php
  $to = 'mail@someshop.com';
  $subject = 'Simple Cart Order';
  $content = $_POST;
  $body = '';
  for($i=1; $i < $content['itemCount'] + 1; $i++) {
  $name = 'item_name_'.$i;
  $quantity =  'item_quantity_'.$i;
  $price = 'item_price_'.$i;
  $body .= 'item #'.$i.': ';
  $body .= $content[$name].' '.$content[$quantity].' '.$content[$price];
  $body .= '<br>';
  }
  $headers = 'From: webmaster@example.com' . "\r\n" .
             'Reply-To: webmaster@example.com' . "\r\n" .
             'X-Mailer: PHP/' . phpversion();
  mail($to, $subject, $body, $headers);
  Header('Location: thankyou.php');
  ?>

有点难过,因为这次没有人帮忙,甚至没有关心!:(

http://www.adamedoe.com/2012/11/simplecartjs-v3-php-code-for-sendform.html

于 2012-11-16T09:17:16.227 回答
1

@adamae 我有一个可行的解决方案,可以向管理员和访问者发送成功的电子邮件,但问题是访问者收到一些可变数据为空,我特此附上表格和 php 文件,请仔细阅读,看看问题出在哪里

所以电子邮件结帐代码:

emailCheckout=function(){alert("====== FINISH YOUR SHOPPING ======\n\nThank you for purchasing our product.\nWe need your data to delivery our product. \n\nPlease, enter your data in to the next box, \n\n-------------- Press OK to continue --------------");var b=prompt("Enter your Email for invoice order: ");var bb=prompt("Enter your name: ");var bbb=prompt("Enter your address: ");var bbbb=prompt("Enter your phone number, I will call or send you a message about the product you purchase: ");itemsString="";esubtotal=0;etotal=0;for(var c in this.items){var d=this.items[c];esubtotal=Math.round(d.quantity*d.price*100)/100;itemsString+=d.quantity+" x "+ d.name+" --> "+ d.quantity+" x Rp."+ d.price+" = Rp."+ String(esubtotal)+"
";etotal+=esubtotal} etotal=Math.round(etotal*100)/100;itemsString+="
Total: Rp."+ String(etotal);var e=document.createElement("form");e.style.display="none";e.method="POST";e.action="http://dorivrach.site90.net/sendjs.php";e.acceptCharset="utf-8";e.appendChild(a.createHiddenElement("jcitems",itemsString));e.appendChild(a.createHiddenElement("jcremite",b));e.appendChild(a.createHiddenElement("buyername",bb));e.appendChild(a.createHiddenElement("buyeralamat",bbb));e.appendChild(a.createHiddenElement("buyerhp",bbbb));e.appendChild(a.createHiddenElement("email",this.email));e.appendChild(a.createHiddenElement("catatanTambahanInvoice",this.catatanTambahanInvoice));e.appendChild(a.createHiddenElement("formatsmsKonfirmasi",this.formatsmsKonfirmasi));e.appendChild(a.createHiddenElement("contohformatsmsKonfirmasi",this.contohformatsmsKonfirmasi));e.appendChild(a.createHiddenElement("urlWebsite",this.urlWebsite));e.appendChild(a.createHiddenElement("alamatPemilik",this.alamatPemilik));e.appendChild(a.createHiddenElement("noHP",this.noHP));e.appendChild(a.createHiddenElement("urlFacebook",this.urlFacebook));e.appendChild(a.createHiddenElement("urlTwitter",this.urlTwitter));e.appendChild(a.createHiddenElement("akunbank1",this.akunbank1));e.appendChild(a.createHiddenElement("norek1",this.norek1));e.appendChild(a.createHiddenElement("namarek1",this.namarek1));e.appendChild(a.createHiddenElement("akunbank2",this.akunbank2));e.appendChild(a.createHiddenElement("norek2",this.norek2));e.appendChild(a.createHiddenElement("namarek2",this.namarek2));e.appendChild(a.createHiddenElement("akunbank3",this.akunbank3));e.appendChild(a.createHiddenElement("norek3",this.norek3));e.appendChild(a.createHiddenElement("namarek3",this.namarek3));e.appendChild(a.createHiddenElement("akunbank4",this.akunbank4));e.appendChild(a.createHiddenElement("norek4",this.norek4));e.appendChild(a.createHiddenElement("namarek4",this.namarek4));e.appendChild(a.createHiddenElement("akunbank5",this.akunbank5));e.appendChild(a.createHiddenElement("norek5",this.norek5));e.appendChild(a.createHiddenElement("namarek5",this.namarek5));e.appendChild(a.createHiddenElement("akunbank6",this.akunbank6));e.appendChild(a.createHiddenElement("norek6",this.norek6));e.appendChild(a.createHiddenElement("namarek6",this.namarek6));e.appendChild(a.createHiddenElement("businessName",this.businessName));e.appendChild(a.createHiddenElement("urlreferrer",this.urlReferrer));document.body.appendChild(e);e.submit();document.body.removeChild(e);return};

<SCRIPT type='text/javascript'>

simpleCart.email = 'abc@gmail.com';
simpleCart.checkoutTo = Email;
simpleCart.currency = INR;
simpleCart.urlWebsite = 'www.abc.blogspot.com';
simpleCart.taxRate = 0.00;
simpleCart.shippingFlatRate = 0.00;
simpleCart.shippingQuantityRate = 1.00;
simpleCart.alamatPemilik = 'sco # 361 ,city-zarakpur , state-punjab , country-India ';
simpleCart.noHP = '+911234567899';
simpleCart.urlFacebook = 'http://www.facebook.com/pages/your facebook';
simpleCart.urlTwitter = 'https://twitter.com/your twitter';
simpleCart.akunbank1 = 'abcdef bank';
simpleCart.norek1 = '55113361232';
simpleCart.namarek1 = 'abc xyz ';

simpleCart.akunbank2 = 'aef bank';
simpleCart.norek2 = '55555361232';
simpleCart.namarek2 = 'abc xyz ';

simpleCart.akunbank3 = 'cdef bank';
simpleCart.norek3 = '55133331232';
simpleCart.namarek3 = 'abc xyz ';



simpleCart.akunbank4 = 'abc bank';
simpleCart.norek4 = '55100001232';
simpleCart.namarek4 = 'abc xyz ';

simpleCart.akunbank5 = 'abcd bank';
simpleCart.norek5 = '55113360098';
simpleCart.namarek5 = 'abc xyz ';

simpleCart.akunbank6 = 'abcde bank';
simpleCart.norek6 = '55113360000';
simpleCart.namarek6 = 'abc xyz ';



simpleCart.urlReferrer = 'http://www.abc.blogspot.com';
simpleCart.businessName = 'abc xyz';
simpleCart.formatsmsKonfirmasi= '(Name, Email, transfer amount, name of bank and branch  where you did transfer, Transfer DATE)';
simpleCart.contohformatsmsKonfirmasi= 'xyz, xyz@xyz.com, INR 1500 , abc-qwerty , 12 December 2012 ';
simpleCart.catatanTambahanInvoice= '(Have a nice day for you and I hope you enjoy it)';
simpleCart.cartHeaders = ["Name", "thumb_image" , "Quantity_input" , "Total", "remove" ];




</SCRIPT>

和 sendhs.php 代码:

<?php
/* sending e-mail with the order to the visitors email*/

$to
= $_POST['jcremite'];

$subject = 'Order copy from domain';

$jcitems = '<body style="background-color: #333333; none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">
<table align="center" bgcolor="#ffffff" border="0" cellpadding="10" cellspacing="0" width="600"> 
<tbody>

<tr style="background-color: #333333">

<td bgcolor="#F3F3F3" style="margin: 4px; padding: 4px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;">This email is a notification email because you or someone with your email have ordered products on our website <a href="'.$_POST['urlWebsite'].'">' .$_POST['businessName'].' </a><br /></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="background-color: rgb(191, 49, 26);">
<table border="0" cellpadding="12" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="1" rowspan="1" style="text-align: center;"><big style="color: white; font-family: Arial Black;"><big>ORDER INVOICE</big></big><span style="font-weight: bold; color: white; font-family: Times New Roman,Times,serif;">&nbsp;</span><br />
<small style="font-family: Verdana;"><span style="color: white; font-weight: bold;">Welcome To Our Online Store</span></small></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="center"><br />
</td>
</tr>
<tr>
<td align="center">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tbody>
<tr>
<td valign="top" width="324">
<h1 style="font-family: Arial,Helvetica,sans-serif; font-size: 20px; padding-bottom: 2px; margin-bottom: 2px; margin-top: 7px; padding-top: 7px; color: rgb(191, 49, 26); text-align: left; font-weight: normal;">Hello '. $_POST['buyername'] . ', </h1>
<p style="margin: 0pt; padding: 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">&nbsp;</p>
<p style="margin: 0pt; padding: 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Thank you for visiting and making a purchase at our Store '. $_POST['businessName'] . '</p>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Here are the goods that you ordered from our website: :</p>
<table style="background-color: rgb(204, 0, 0); width: 324px;" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="text-align: center;"><span style="color: white; font-weight: bold;">YOUR ORDER </span>
</td>
</tr>
<tr style="background-color: rgb(204, 0, 0);">
<td style="background-color: rgb(238, 238, 238);">
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">'. $_POST['jcitems'] . '</p>
</td>
</tr>
</tbody>
</table>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Please make a note that: <b>The price does not include postage.</b>. We will contact you via SMS or EMAIL to inform the total cost that you have to transfer. Once you get a confirmation from us, please make payment via bank listed in the mode of payment box, and then do a confirmation in the following format:  :</p>
<table style="text-align: left; background-color: white; width: 321px; height: 100px;" border="0" cellpadding="10" cellspacing="2">
<tbody>
<tr style="color: black;">
<td style="background-color: rgb(204, 204, 204); "><p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">'. $_POST['formatsmsKonfirmasi'] . '</span></p></td>
</tr>
<tr style="color: black;">
<td style="background-color: rgb(153, 153, 153);">
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">
<strong>Example : </strong>'. $_POST['contohformatsmsKonfirmasi'] . '</p>
</td>
</tr>
<tr style="color: black;">
<td style="background-color: silver;">
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Then SMS me at: '. $_POST['noHP'] . '</span></small></p>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">or email me at email addres : <br>
'. $_POST['email'] . '</span></p>
</td>
</tr>
</tbody>
</table>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Thank you for visting and shopping at our online Store '. $_POST['businessName'] . '</p>

<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Please do not hesitate to tell others if you liked our products and services and tell us if the products were not of that quality which you expected or there were some faults in our services . Your feedback is important for us to grow high so be in touch and we are awaiting your next kind visit to our online store.</p>

<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;">Regards :</p>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: left;"><b>'. $_POST['businessName'] . '</b><br />
<span style="font-style: italic;">'. $_POST['urlWebsite'] . '</span></p>
<br/><br/><hr>
<p style="font-family: Arial,Helvetica,sans-serif; font-size: 10px; color: rgb(51, 51, 51); text-align: left;"></p>
<div style="text-align: center;"><p style="font-family: Arial,Helvetica,sans-serif; font-size: 18px; text-align: center;">ATTENTION!!</p>
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;">Be carefull before buying, goods bought once can not be exchanged or refunded
<br /></div>
</td>
<td valign="top">
<table style="padding-top: 5px; margin-top: 5px;" border="0" cellpadding="10" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="center" style="border-left: 2px solid rgb(191, 49, 26);"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-weight: bold;">Your personal data<br />--------------------------------------</span><br />
<big><font size="-2"><big><span style="font-weight: bold;"></span></big></font></big></span>
<table style="text-align: center; width: 100%;" border="0" cellpadding="5" cellspacing="2">
<tbody>
<tr>
<td style="background-color: rgb(204, 204, 204);"><p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;"><strong>Name : </strong><br />
'. $_POST['buyername'] .' </p></td>
</tr>
<tr align="center">
<td style="background-color: rgb(228, 228, 228);"><p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;"><strong>Email:</strong><br />
'. $_POST['jcremite'] . '</p></td>
</tr>
<tr align="center">
<td style="background-color: silver;"><p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;"><strong>Address:</strong><br />
'. $_POST['buyeralamat'] . '</p></td>
</tr>
<tr align="center">
<td style="background-color: rgb(228, 228, 228);"><p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: rgb(51, 51, 51); text-align: center;"><strong>Phone Number : </strong><br /> 
'. $_POST['buyerhp'] . '</p></td>
</tr>
</tbody>
</table>
<span style="font-family: Arial,Helvetica,sans-serif;"><big><font size="-2"><big><br />
</big></font></big></span></td>
</tr>
</tbody>
</table>
<br />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="background-color: rgb(191, 49, 26);">
<h2 style="margin: 8px 8px 0pt; padding: 8px 8px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 15px; color: rgb(255, 255, 255); font-weight: bold; text-align: center;"><big>Mode of Payment
</big><br />
</h2>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;">You can make a payment through any of the following banks&nbsp;</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;">----------------------------------------------</p>

<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank1'] . '</span></big><br />'. $_POST['namarek1'] . '<br />'. $_POST['norek1'] . '</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank2'] . '</span></big><br />
'. $_POST['namarek2'] . '<br />
'. $_POST['norek2'] . '</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank3'] . '</span></big><br />
'. $_POST['namarek3'] . '<br />
'. $_POST['norek3'] . '</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank4'] . '</span></big><br />
'. $_POST['namarek4'] . '<br />
'. $_POST['norek4'] . '</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank5'] . '</span></big><br />
'. $_POST['namarek5'] . '<br />
'. $_POST['norek5'] . '</p>
<p style="margin: 0pt 8px 8px; padding: 0pt 8px 8px; font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(255, 255, 255); text-align: center;"><big><span style="font-weight: bold;">'. $_POST['akunbank6'] . '</span></big><br />
'. $_POST['namarek6'] . '<br />
'. $_POST['norek6'] . '</p>
</td>
</tr>
</tbody>
</table>



</td>


</tr>

</tbody>

</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tbody>


<tr>


<td>

</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr style="background-color: rgb(106, 104, 102);">
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>

<tr style="font-family: Arial,Helvetica,sans-serif; font-size: 11px; color: rgb(255, 255, 255); text-align: center;">

<td colspan="1" rowspan="1"><p>Thanks again for your kind visit to : <em><strong>OUR ONLINE STORE</strong></em><br />
<p style="margin: 4px 0pt; padding: 4px 0pt; font-family: Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px; color: orange; text-align: left;">* Do you have any questions? then please do not hesitate emailing me at '. $_POST['email'] . '</p><br />

<a href="'. $_POST['urlWebsite'] . '" style="color: white;"><strong>&gt;&gt;LINK TO OUR ONLINE STORE : '. $_POST['businessName'] . '  &lt;&lt;</strong></a><br />

</span></td>

</tr>
</tbody>
</table>
</td>
</tr> </tbody></table></body>';
$headers = 'From: ' . $_POST['businessName'] . '<' . $_POST['email'] . '>'."\r\n" ;

'Reply-To:' . $_POST['email'] . "\r\n" ;
$headers .= 'MIME-Version: 1.0' . "\r\n";   $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $jcitems, $headers); 


// /* sending e-mail to the shop email */   
$to
= $_POST['email'];  $subjectAdmin = 'NEW ORDER';    $jcitemsAdmin = '<html><body>Hello Admin, there was a visitor at your online store <b>' . $_POST['businessName'] . '</b><br/><br/> Here are the goods ordered by the visitor :<br/>' . $_POST['jcitems'] . '<br/>    <br/>Here is the brief data of the visitor :   <br/>===============================================    <br/>Email : ' . $_POST['jcremite'] . '<br/>Name : ' . $_POST['buyername'] .    '<br/>Address :'. $_POST['buyeralamat'] . '<br/>Phone Number : '. $_POST['buyerhp'] . '<br/>===============================================  <br/><br/> It is suggested that you contact your customers via EMAIL and SMS to inform them about TOTAL cost to be transferred (including postage), do not wait until they are contact you first, because more than 60% of visitors are passive consumers and window shoppers . Therefore we recommend  you  to send SMS or / and EMAIL to visitors. 

<br/><br/>Have a nice day!</body></html>';  $headers = 'From: visitors email <'.$_POST['jcremite'].'>'."\r\n" ;

'Reply-To:' . $_POST['jcremite'] . "\r\n" ; $headers .= 'MIME-Version: 1.0' . "\r\n";   $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subjectAdmin, $jcitemsAdmin, $headers);


/*Clearing the cart info after succesfull order is made*/

setcookie ("simpleCart", "", time() - 3600);

header('location:' . $_SERVER['HTTP_REFERER'].'p/thank-you.html');

die;

?>

它就像一个魅力

问题仅在于访问者电子邮件中的某些帖子变量为空,请查看代码并查看是否有解决方案:

你也可以给我发邮件chikitsakgupt@gmail.com

于 2013-03-10T09:30:23.647 回答