Hello

I am trying to send mail to customer with the details of product they brought but the code which I have written not showing the value of variable total_list

Actually I need to send email regarding the product details purchased by user if they purchased more than 1 product then user must get 1 mail with all products detail

For this I am trying to do like this

    $cart = $_SESSION['cart'];
    $items = explode(',',$cart);
    $result = count($items);
    $total_list='';
    for ($i=0; $i<$result; $i++)
    {
        //echo $items[$i];
        orderconfirm($items[$i]);
    }

    function orderconfirm($productid)
    {
        $cus_id = $_SESSION['own_email'];
        $pro_id = $productid;
        $result = mysql_query("SELECT * FROM products where id = '$pro_id'");
        if($row = mysql_fetch_array($result))
        {
        $subject = $row['Subjects'];
        $main_proname = $row['mainproduct']; 
        $proname = $row['p_name'];  
        $prodetail = $row['details'];   
        $proprince = $row['prince'];
        }
        $holder = $_POST['holder'];
        $bank = $_POST['bank'];
        $branch = $_POST['branch'];
        $ac_no = $_POST['ac_no'];
        $cheqdate = $_POST['cheqdate'];
        $cheq_no = $_POST['cheq_no'];
        $total_amount = $_POST['tota_amount'];

        $total_list = $proname.'-'.$main_proname.'-'.$proprince.'<br />';

    /*  $qry = "INSERT INTO `sales_data`(`cust_id` , `subject` , `pro_id` , `mainproduct` , `pro_name` , `prince` , `bank` , `cheque_no` , `holder_name` , `branch` , `ac_no` , `cheqdate` , `paid` )
         VALUES ('$cus_id', '$subject', '$pro_id', '$main_proname', '$proname', '$proprince', '$bank', '$cheq_no', '$holder', '$branch', '$ac_no', '$cheqdate', 'no')";

        echo $qry; 



        $coloer1 = '';
        if (!mysql_query($qry))
          {
          die('Error: ' . mysql_error());
          } */

    }
    echo $total_list;


    //unset($_SESSION['cart']);
    //$_SESSION['cart']=='';
    //echo "1 record added";
    //header("Location: thankyou.php");
        //exit();
    ?>

Thank you all

Recommended Answers

All 3 Replies

please also check the value of $result by echoing it
because for loop execution is based on this value

if the vaue of the $result variable is '0' then there is nothing to display

so please check & echo the value of $result variable also

happy coding

I changed you line number 8 in your code and I added last line in ur orderconfirm function

    $cart = $_SESSION['cart'];
    $items = explode(',',$cart);
    $result = count($items);
    $total_list='';
    for ($i=0; $i<$result; $i++)
    {
        //echo $items[$i];
        $total_list=$total_list."<br>".orderconfirm($items[$i]); //URTRIVEDI MODIFIED THIS LINE
    }

    function orderconfirm($productid)
    {
        $cus_id = $_SESSION['own_email'];
        $pro_id = $productid;
        $result = mysql_query("SELECT * FROM products where id = '$pro_id'");
        if($row = mysql_fetch_array($result))
        {
        $subject = $row['Subjects'];
        $main_proname = $row['mainproduct']; 
        $proname = $row['p_name'];  
        $prodetail = $row['details'];   
        $proprince = $row['prince'];
        }
        $holder = $_POST['holder'];
        $bank = $_POST['bank'];
        $branch = $_POST['branch'];
        $ac_no = $_POST['ac_no'];
        $cheqdate = $_POST['cheqdate'];
        $cheq_no = $_POST['cheq_no'];
        $total_amount = $_POST['tota_amount'];

        $total_list = $proname.'-'.$main_proname.'-'.$proprince.'<br />';

    /*  $qry = "INSERT INTO `sales_data`(`cust_id` , `subject` , `pro_id` , `mainproduct` , `pro_name` , `prince` , `bank` , `cheque_no` , `holder_name` , `branch` , `ac_no` , `cheqdate` , `paid` )
         VALUES ('$cus_id', '$subject', '$pro_id', '$main_proname', '$proname', '$proprince', '$bank', '$cheq_no', '$holder', '$branch', '$ac_no', '$cheqdate', 'no')";

        echo $qry; 



        $coloer1 = '';
        if (!mysql_query($qry))
          {
          die('Error: ' . mysql_error());
          } */
        return $total_list; //URTRIVEDI ADDED THIS LINE
    }
    echo $total_list;


    //unset($_SESSION['cart']);
    //$_SESSION['cart']=='';
    //echo "1 record added";
    //header("Location: thankyou.php");
        //exit();
    ?>

Thank you URTRIVEDI its done

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.