title: Retrieve data from cart and send using mail
body: <p>This project is with E-Commerce. There is option to <strong><em>Add to Cart</em></strong>. When user click on add, product will be added to his cart as well and working fine.</p>
  
  <p>But finally when user click <strong>place order</strong> button Admin will receive Mail with products. That E-mail body should content should display like below. </p>
  
  <p><img src="https://i.stack.imgur.com/dT88C.png" alt="Image"></p>
  
  <p>I tried with using <code>foreach</code> and <code>echo</code> data row by row. But its useless . </p>
  
  <p><strong>Question is</strong> - I want retrieve data from cart and add to Above table Format and then it will end with mailing.  How to archive this with CI?</p>
  
  <p><strong>Html</strong> Table Format</p>
  
  <pre><code>$to = 'mail@gmail.com';
                      $msg .= '
                          &lt;table id="table" border="0" cellpadding="5px" cellspacing="1px"  style="border: 1px solid #eee"&gt;
                              &lt;tr id= "main_heading"&gt;
                                  &lt;td&gt;Name&lt;/td&gt;
                                  &lt;td&gt;Price&lt;/td&gt;
                                  &lt;td&gt;Qty&lt;/td&gt;
                                  &lt;td&gt;Amount&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;';
  </code></pre>
  
  <p><strong>Note</strong> : there is no special code to this(inserting and updating). all the codes are same with <a href="https://ellislab.com/codeigniter/user-guide/libraries/cart.html" rel="nofollow noreferrer">ellislab.com</a></p>
  
  <p><strong>CART VIEW</strong></p>
  
  <p><img src="https://i.stack.imgur.com/qSTHm.png" alt="Cart view"></p>
  
  <p>If i use </p>
  
  <pre><code>$as = $this-&gt;cart-&gt;contents();
  print_r($as);
  </code></pre>
  
  <p>it shows </p>
  
  <p><img src="https://i.stack.imgur.com/2MtLR.png" alt="Array"></p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function index()
          {
              $data['category'] = $this-&gt;Product_Model-&gt;get_category();
              $data['category2'] = $this-&gt;Product_Model-&gt;get_category2();
              $data['product'] = $this-&gt;Product_Model-&gt;get_product();
              $data['right_brand'] = $this-&gt;Product_Model-&gt;get_right_brand();
  
              $data['right_prod'] = $this-&gt;Product_Model-&gt;get_right_product();
              $data['brand'] = $this-&gt;Product_Model-&gt;get_brand_names();
  
              $data['products'] = $this-&gt;Product_Model-&gt;get_cart_items();
              $data['head'] = $this-&gt;Product_Model-&gt;check_cart();
  
              $this-&gt;load-&gt;view('template/header', $data);
              $this-&gt;load-&gt;view('template/right_sidebar', $data);
              $this-&gt;load-&gt;view('pages/cart', $data);
              $this-&gt;load-&gt;view('template/foot');
  
  
          }
  
          public function insert_cart()
          {
  
              $data = array(
                  'id'    =&gt; $this-&gt;input-&gt;post('pid'),
                  'qty'   =&gt; $this-&gt;input-&gt;post('qty'),
                  'price' =&gt; $this-&gt;input-&gt;post('price'),
                  'name'  =&gt; $this-&gt;input-&gt;post('head'),
              );
  
              $this-&gt;cart-&gt;insert($data);    
          }
  
          function remove($rowid)
          {
              if ($rowid==="all")
              {
                  $this-&gt;cart-&gt;destroy();
                  redirect('index.php/main');
              }
              else
              {
                  $data = array(
                      'rowid'   =&gt; $rowid,
                      'qty'     =&gt; 0
                  );
                  $this-&gt;cart-&gt;update($data);
              }
  
              // This will show cancle data in cart.
              redirect('index.php/cart');
          }
  
          function update_cart()
          {
  
              $cart_info =  $_POST['cart'] ;
              foreach( $cart_info as $id =&gt; $cart)
              {
                  $rowid = $cart['rowid'];
                  $qty = $cart['qty'];
  
                  $data = array(
                      'rowid'   =&gt; $rowid,
                      'qty'     =&gt; $qty
                  );
  
                  $this-&gt;cart-&gt;update($data);
              }
              redirect('index.php/cart');
          }
  </code></pre>