购物车到电子邮件

发布于 2024-08-22 11:22:14 字数 265 浏览 5 评论 0原文

我使用 simplecartjs 在我的网站上创建一个购物车,您可以在其中选择元素并将其发送到您的购物车...下一步将是结账流程,但出于业务原因,不会附加结账流程,并且会询问一份包含姓名、电子邮件和订单取货日期的简单表格。现在,订单必须发送到将完成订单的电子邮件地址(公司内)。

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

I use simplecartjs to make a shopping cart on my website where you can select element and send it to your cart... next step, will be the checkout process, but for business reason, no checkout process will append, and a simple form with name and email and date for order pickup will be ask. Now the order must be send to an email address (at the company) that will fullfill the order.

The question : how to send the content of the cart to an email body or as attachement ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯离梦残月幽梦 2024-08-29 11:22:14

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

在结帐期间检查用户是否已注册,如果没有,将重定向到注册。

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

将向店主发送 2 封电子邮件“[email protected]”并发送到用户电子邮件,以便他看到订单

成功订单后,需要为感谢部分制作一个新页面

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      = '[email protected]';
        $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: [email protected]' . "\r\n" .
                   'Reply-To: [email protected]' . "\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 \[email protected]";
        $headers = 'From: [email protected]' . "\r\n" .
                   'Reply-To: [email protected]' . "\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; }   ?>

中您将需要 WordPress 的 Register Plus 插件来添加额外的内容用户“电话和地址”的 2 个字段
请务必检查
添加注册字段
添加个人资料字段
必需的

This Will add the email order, suplimentary fields to the user "Phone and Adress",

Check during the CheckOut the the user is registered if not will redirect to registration.

WILL CLEAR Shopping cart only after succesful email order sent.

Will send 2 e-mail to the shop owner "[email protected]" and to the users email so he sees the order

Will need to make a new page for the Thank You part after succesful order is made

simplecartjs: around line 288 is in mine

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      = '[email protected]';
        $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: [email protected]' . "\r\n" .
                   'Reply-To: [email protected]' . "\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 \[email protected]";
        $headers = 'From: [email protected]' . "\r\n" .
                   'Reply-To: [email protected]' . "\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; }   ?>

You will need Register Plus plugin for wordpress to add the extra 2 fiels to the user "phone and address"
be sure to check
Add Registration Field
Add Profile Field
Required

遗忘曾经 2024-08-29 11:22:14

您应该向 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);
}

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

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

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

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

You should add new checkout method to 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);
}

This will create new form element and submit cart data to sendjs.php. Enable this checkout method by setting me.checkoutTo = 'Email' in simplecart options.

Now create a new sendjs.php file:

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

This will send the email message and redirect to thankyou.html page you should also create.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文