如何通过php将订单发送给客户

时间:2011-12-18 19:01:29

标签: php mysql email shopping-cart

这是一个编辑,我已插入导航请求的更新代码下方。

产品未通过电子邮件发送给客户电子邮件。我已经尝试了一切,但找不到解决方案。

 <?
    include("includes/db.php");
    include("includes/functions.php");  

    $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $price=get_price($pid);
            $date=date('Y/m/d');
            $user=$_SESSION['username'];
            $pname=get_product_name($pid);
            mysql_query("insert into `order` values ('','$pname','$q','$price','$date','$user')")

                or die(mysql_error());
                        }

        die('Thank You! your order has been placed! <br/> <a  href="login/order.php">Home</a>');
        /*session_unset(); */
        session_unset($_SESSION['cart']);

        session_destroy($_SESSION['cart']);

?>

<?php 
$con = mysql_connect("localhost","*****","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('********', $con);

$sql="SELECT * FROM customers WHERE username = '".$_SESSION['username']."'";//"CUSTOMERS ID" = the customer who you would like to email, their id from the DB

$q=mysql_query($sql,$con);

$r=mysql_fetch_array($q);

$messege = "Hi $user, <br/><br/> You Have Ordered The Following Items on $date :<br/> <br/>$pname <br/> $q <br/> $price  ";
$to= $r['email'];
$from = 'order@musicinc.com';
$subject="Your Order Has Been Placed";
mail($to,$subject,$messege,$from);

?>

我尝试没有数据库查询并插入我的Gmail,但根本没有成功。

EDITED

2 个答案:

答案 0 :(得分:0)

试试这个:

$messege = "Your email here....";
$to="the recipient (customer) here";
$from "your email address";
$subject="subject here";
mail($to,$subject,$messege,$from);

这应该可以解决问题。

数据库查询(您应该在问题中提问....):

$con=mysql_connect($host,$user,$password);//make the appropriate changes to the variables..

$sel="SELECT * FROM customers WHERE id='CUSTOMER ID'";//"CUSTOMERS ID" = the customer who you would like to email, their id from the DB

$q=mysql_query($sel,$con);

$r=mysql_fetch_array($q);

修改

function email_customer($to=""){
$messege = "Hi $user, <br/><br/> You Have Ordered The Following Items on $date :<br/> <br/>$pname <br/> $q <br/> $price  ";
$from = "order@musicinc.com";
$subject="Your Order Has Been Placed";
mail($to,$subject,$messege,"From: $from");
}; 

email_customer($r['email']);

以上基本相同,只是在函数中。

$r['email'];替换为您自己的电子邮件以进行测试:email_customer("your@email.com");

如果这不起作用,则不是代码..

答案 1 :(得分:0)

看起来像Zencart代码(或可能是Oscommerce)。这些内置电话会向客户发送电子邮件,即使您试图破解代码,也可以通过在相关支持论坛上询问您的应用程序来获得最佳服务。