<?php
session_start();
require_once('class/class.phpmailer.php');

$mail = new PHPMailer();

$color=array("#ffffff","#F0F0F0");
$contador=0;
$suma=0;

if(isset($_SESSION['carro']))
    $carro=$_SESSION['carro'];
    else $carro=false;


$body ="<table><tr align='center'><td colspan='3'>";
$body .= "<span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; color: #990000; font-weight: bold;'>FACTURA DE COMPRA</span></td></tr>";
$body .= "<tr bgcolor='#333333'><td width=300><span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #FFFFFF;'>PRODUCTO</span></td><td width=100><span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color:#FFFFFF;'>PRECIO</span></td><td width=100><span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #FFFFFF;'>CANTIDAD</span></td></tr>";

foreach($carro as $k){
$subto=$k['cantidad']*$k['precio'];
$suma=$suma+$subto;
$contador++;
$body .= "<tr><td align='left'>". $k['nombre']."</td><td align='right'>".number_format($k['precio'],2)."</td><td align='right'>".$k['cantidad']."</td></tr>";
}
$body .= "<tr bgcolor='#C0C0C0'><td align='left'>Total de Articulos :</td><td align='right'></td><td align='right'>".count($carro)."</td></tr>";
$body .= "<tr bgcolor='#C0C0C0'><td align='left'>Total $:</td><td align='right'></td><td align='right'>".number_format($suma,2)."</td></tr>";
$body .= "</table>";

$Nombre=$_POST['nombre'];
$Email=$_POST['email'];

    
$mail->IsHTML(true); // telling the class to use HTML
$mail->SetFrom($Email, $Nombre);

$address = "ventas@egocar.mx";
$mail->AddAddress($address, "egocar");

$mail->Subject    = "SOLICITUD DE PEDIDO";

$mail->AltBody    = "FACTURA DEL PEDIDO REALIZADO"; // optional, comment out and test

$mail->MsgHTML($body);
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    
 echo "<span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; color: #585858;'>PEDIDO ENVIADO CORRECTAMENTE...  espere unos segundos</span>";

//Para destruir una variable en específico
unset($_SESSION['carro']);
 
// Finalmente, destruye la sesión
session_destroy();

}
?>
<html>
<head>
<title></title>
<script LANGUAGE="JavaScript">
var pagina="../index.html";
function redireccionar(){
  location.href=pagina;
}
setTimeout ("redireccionar()", 2000);
</script> 
</head>
<body>
</body>
</html>


