购物车发送电子邮件

时间:2010-02-16 14:19:48

标签: e-commerce cart

我使用simplecartjs在我的网站上制作购物车,您可以在其中选择元素并将其发送到购物车...下一步,将是结帐流程,但出于商业原因,没有结帐流程将追加,并提供一个简单的表格,其中包含姓名,电子邮件和订单取件日期。现在订单必须发送到将填写订单的电子邮件地址(在公司)。

问题:如何将购物车的内容发送到电子邮件正文或作为附件?

2 个答案:

答案 0 :(得分:2)

这会将电子邮件订单,免费字段添加到用户“电话和地址”,

在CheckOut期间检查用户是否已注册,否则将重定向到注册。

只有在成功发送电子邮件订单后才会清除购物车。

将向店主“shop@domain.com”发送2封电子邮件,并向用户发送电子邮件,以便他看到订单

成功完成订单后,需要为Thank You部分创建一个新页面

simplecartjs:第288行是在我的

me.emailCheckout = function() {    

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

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

sendjs.php

 <?php   require( dirname(__FILE__) . '/wp-load.php' );   
   /* cheking is user is logged in*/ 
   if ( is_user_logged_in() ) { 
    get_currentuserinfo(); /* getting user details*/

/* sending e-mail to the shop email */
        $to      = 'shop@domain.com';
        $subject = 'New Order';
        $jcitems =  " Name: " . $current_user->user_lastname .
                    " \n First Name: " . $current_user->user_firstname .
                    " \n Email: " . $current_user->user_email .
                    " \n Phone: " . $current_user->phone .
                    " \n Adress: " . $current_user->adress ;
        $headers = 'From: shop@domain.com' . "\r\n" .
                   'Reply-To: shop@domain.com' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $jcitems, $headers);

/* sending e-mail with the order to the users email*/        

        $to      = $current_user->user_email;
        $subject = 'Order copy from Domain';
        $jcitems =  "Thank you for you order. Below you have your ordered products".
                    " \n ORDER: \n\n " . $_POST['jcitems'] . "Total: " . $_POST['jctotal'] . " USD" .
                    "\n\n http://www.domain.com \nshop@domain.com";
        $headers = 'From: shop@domain.com' . "\r\n" .
                   'Reply-To: shop@domain.com' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $jcitems, $headers);
        /*Clearing the cart info after succesfull order is made*/
        setcookie ("simpleCart", "", time() - 3600);
        /*redirecting user to Thank you page from Wordpress*/
    Header('Location: http://www.domain.com/thank_you/');  } 

    else { /*sending user to register*/
        header( 'Location: http://www.domain.com/wp-login.php?action=register' ) ; exit; }   ?>

您需要使用Register Plus插件进行wordpress,才能将额外的2个fiels添加到用户“手机和地址”
一定要检查
添加注册字段
添加配置文件字段

答案 1 :(得分:1)

您应该向simplecartjs添加新的结帐方法:

me.emailCheckout = function() {    

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

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

这将创建新的表单元素并将cart数据提交给sendjs.php。通过在simplecart选项中设置me.checkoutTo ='Email'来启用此结帐方法。

现在创建一个新的sendjs.php文件:

<?php
    $to      = 'you@example.com';
    $subject = 'the subject';
    $jcitems = $_POST['jcitems'];
    $headers = 'From: webmaster@example.com' . "\r\n" .
               'Reply-To: webmaster@example.com' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $jcitems, $headers);
    Header('Location: thankyou.html');
?>

这将发送电子邮件并重定向到您应该创建的thankyou.html页面。