Send session to email

0

I need to send a "cart" via email and am using session . Basically I only need products to be sent to an email (gmail).

Thisistheshippingcode.Pleasehelpanewbie!

<?phpinclude("cabecalho.php");
?>

<?php
include("menu.php");
?>


<?php

if(isset($_POST['submit'])){

foreach($_POST['quantity'] as $key => $val) {
                                             if($val==0) {
unset($_SESSION['cart'][$key]);
                               }else{
$_SESSION['cart'][$key]['quantity']=$val;
  }
 }
}

?>

<head>
<link rel="stylesheet" href="css/enctable.css" >
</head>


<div style="color:white ; box-shadow: 3px 3px 10px 5px #000; background: rgba(0, 0, 0, 0.7)">
<center>
<h1>Checkout</h1>
</center>
</div>

<form method="POST"
      action="encomendas.php?page=cart">

<center><div>
<table align="top"><tr>

<th>Suas informações!</th></tr>
<th>Nome: <input type="text" size="35" maxlenght="256" name="nome"></th></tr>
<th>Email: <input type="text" size="35" maxlenght="256" name="email"></th></tr>
<th>CEP: <input type="text" size="35" maxlenght="256" name="cidade"></th></tr>
<th>Telefone: <input type="text" size="35" maxlenght="256" name="estado"></th>

<form action="verifica.php" method="POST">
<tr><th><button type="submit"
                name="submit">Enviar!</button></th></tr>
</form>
</table>

<table cellspacing="10">
<tr>
<br>
    <th>Nome&nbsp;</th>
    <th>Quantidade&nbsp;</th>
    <th>Valor&nbsp;</th>
    <th>Valor do Item&nbsp;</th>
</tr>


<?php

if(isset($_SESSION['cart'])){

$sql="SELECT * FROM products WHERE id_product IN (";

  foreach($_SESSION['cart'] as $id => $value) {
  $sql.=$id.",";
                }

  $sql=substr($sql, 0, -1).") ORDER BY name ASC";

  $query=mysql_query($sql);

  $totalprice=0;

  while($row=mysql_fetch_array($query)){
  $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price'];
  $totalprice+=$subtotal;
  ?>

  <tr>
      <td><?php echo $row['name']  ?> </td>
      <td><input name="quantity[<?php echo $row['id_product'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>" /></td>
      <td><?php echo $row['price'] ?>R$</td>
      <td><?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?><font size="6"> &nbsp;R$</td>
<?php

}

?>
    <tr><th colspan="4">
    <p>Valor total: <?php echo $totalprice ?><font size="5">&nbsp; &nbsp;R$</></p></th><tr>

<?php
}

else {

 $redirect = "http://localhost/Padaria23/zerado.php";
 header("location:$redirect");

}
?>

</table>
    
asked by anonymous 17.10.2015 / 05:04

1 answer

0

If you just want to send the entire contents of your SESSION via email, you can do the following:

print_r($_SESSION, true)

Now, if you want to send in an HTML message, make a foreach in your SESSION and for each iteration throw the content in variable or array:

foreach($_SESSION[carrinho] as $item)
{

$arItem[] = "Produto: ".$item[produto]." - Valor: R$ ".$item[valor];

}

$conteudoEmail = implode("<br>", $arItem);
    
23.10.2015 / 14:45