Sending from Session to email

Asked

Viewed 141 times

0

I need to send a "cart" via email and I’m using a session.
Basically I just need the products to be sent to an email (gmail). inserir a descrição da imagem aqui

This is the shipping code. Please help a newbie!

<?php
include("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>
  • Where exactly is the code that sends the email?

  • What is done of the function that sends the email ?

  • This one would be email.php, but I don’t know if it works, because I’ve never performed the email sending procedure. And I still need to submit the request which is not contained there. Thank you very much for your attention! <? php $to = "[email protected]"; $Subject = "Request"; $txt = "A new request has been made." ; mail ($to,$Subject,$txt); echo "Request sent!" ; ?>

  • <?php $to = "[email protected]"; $Subject = "Request"; $txt = "A new request has been made." ; mail ($to,$Subject,$txt); echo "Sent Request!" ; ?>

1 answer

0

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

print_r($_SESSION, true)

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

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

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

}

$conteudoEmail = implode("<br>", $arItem);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.