Attaullah Khan
Attaullah Khan

Reputation: 41

how to send codeigniter cart data on email

hello guys I tried to much to send codeigniter cart data on mail, it woking but I need to send it on html table.plz help me

 if($cart = $this->cart->contents()){
    foreach ($cart as $item){
      $htmlContent=array(
      'orderid'=>$user_id,
     "product name":  ".$item['name'],  
      );
      $dataset[] = implode(', ', $htmlContent);
     }   
  }
  $content = implode("\n<br>", $dataset);
  $headers  = 'MIME-Version: 1.0' . "\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
  $headers .= 'From:[email protected]'."\n";
  mail('[email protected]', $subject, $content , $headers);

Upvotes: 0

Views: 328

Answers (1)

Razib Al Mamun
Razib Al Mamun

Reputation: 2711

Please follow bellow code:

<?php
$content = '<table cellpadding="6" cellspacing="1" style="width:100%" border="0">';

$content .= '<tr>';
        $content .= '<th>QTY</th>';
        $content .= '<th>Item Description</th>';
        $content .= '<th style="text-align:right">Item Price</th>';
        $content .= '<th style="text-align:right">Sub-Total</th>';
$content .= '</tr>';

$i = 1;
foreach ($this->cart->contents() as $items):
        $content .= '<tr>';
                $content .= '<td>'.$items['qty'].'</td>';
                $content .= '<td>'.$items['name'];
                        if ($this->cart->has_options($items['rowid']) == TRUE):                            
                                $content .= '<p>';

                                        foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value):

                                                $content .= '<strong>'.$option_name.':</strong>'.$option_value.'<br />';

                                        endforeach;
                                $content .= '</p>';
                        endif;
                $content .= '</td>';
                $content .= '<td style="text-align:right">'.$this->cart->format_number($items['price']).'</td>';
                $content .= '<td style="text-align:right">$'.$this->cart->format_number($items['subtotal']).'</td>';
        $content .= '</tr>';
$i++; 
endforeach;

$content .= '<tr>';
        $content .= '<td colspan="2"> </td>';
        $content .= '<td class="right"><strong>Total</strong></td>';
        $content .= '<td class="right">$'.$this->cart->format_number($this->cart->total()).'</td>';
$content .= '</tr>';

$content .= '</table>';

$headers  = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'From:[email protected]'."\n";
mail('[email protected]', $subject, $content , $headers);
?>

Upvotes: 2

Related Questions