• User Newbie

    Problemi con Invio E-Mail degli ordini effettuati

    Salve amici spero di risolvere il mio problema .Ho creato da vari sript un modulo ordini con carrello della spesa perfettamente funzionante, i prodotti vengono estratti da un database MySql.
    Una volta arrivato all'invio dell'ordine, mi arriva una mail vuota o quantomeno riesco solo a vedere gli ID dei prodotti (1,5,8,5,3 e cosi via)
    come posso fare per inviare il carrello della spesa completo di totale?
    Vi ringrazio anticipatamente per il vostro supporto

    questi i file:

    questa è la pagina dove risiede il carrello:
    [PHP]
    ?php
    // Include MySQL class
    require_once('inc/mysql.class.php');
    // Include database connection
    require_once('inc/global.inc.php');
    // Include functions
    require_once('inc/functions.inc.php');
    // Start the session
    session_start();
    // Process actions
    $cart = $_SESSION['cart'];
    $action = $_GET['action'];
    switch ($action) {
    case 'add':
    if ($cart) {
    $cart .= ','.$_GET['id'];
    } else {
    $cart = $_GET['id'];
    }
    break;
    case 'delete':
    if ($cart) {
    $items = explode(',',$cart);
    $newcart = '';
    foreach ($items as $item) {
    if ($_GET['id'] != $item) {
    if ($newcart != '') {
    $newcart .= ','.$item;
    } else {
    $newcart = $item;
    }
    }
    }
    $cart = $newcart;
    }
    break;
    case 'update':
    if ($cart) {
    $newcart = '';
    foreach ($_POST as $key=>$value) {
    if (stristr($key,'qty')) {
    $id = str_replace('qty','',$key);
    $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
    $newcart = '';
    foreach ($items as $item) {
    if ($id != $item) {
    if ($newcart != '') {
    $newcart .= ','.$item;
    } else {
    $newcart = $item;
    }
    }
    }
    for ($i=1;$i<=$value;$i++) {
    if ($newcart != '') {
    $newcart .= ','.$id;
    } else {
    $newcart = $id;
    }
    }
    }
    }
    }
    $cart = $newcart;
    break;
    }
    $_SESSION['cart'] = $cart;
    ?>

    <?php
    echo writeShoppingCart();
    ?>
    <?php
    echo showCart();
    ?>
    <?php
    echo $total;
    ?>
    [/PHP]

    la struttura del database:

    
    CREATE TABLE menu ( Id INT(11) NOT NULL PRIMARY KEY, prodotto VARCHAR(255), ingrediente VARCHAR(255), prezzo decimal(10,2)  );
    

    il file function.php
    [PHP]
    <?php
    function writeShoppingCart() {
    $cart = $_SESSION['cart'];
    if (!$cart) {
    return '<p>Non hai nessun prodotto nel carrello</p>';
    } else {
    // Parse the cart session variable
    $items = explode(',',$cart);
    $s = (count($items) > 1) ? '/i':'';
    return '<p>Tu hai <a href="pagina1.php">'.count($items).' prodotto'.$s.' nel tuo carrello della spesa</a></p>';
    }
    }

    function showCart() {
    global $db;
    $cart = $_SESSION['cart'];
    if ($cart) {
    $items = explode(',',$cart);
    $contents = array();
    foreach ($items as $item) {
    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
    }
    $output[] = '<form action="?action=update" method="post" id="cart">';
    $output[] = '<table>';
    foreach ($contents as $id=>$qty) {
    $sql = 'SELECT * FROM menu WHERE id = '.$id;
    $result = $db->query($sql);
    $row = $result->fetch();
    extract($row);
    $output[] = '<tr>';
    $output[] = '<td><a href="?action=delete&id='.$id.'" class="r">Cancella</a></td>';
    $output[] = '<td><strong><font color="#FF00">'.$prodotto.'</font></strong><br/><font color="#8C8C8C">'.$ingredienti.'</font></td>';
    $output[] = '<td>€'.$prezzo.'</td>';
    $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
    $output[] = '<td>€'.($prezzo * $qty).'</td>';
    $total += $prezzo * $qty;
    $output[] = '</tr>';
    }
    $output[] = '</table><br/>';
    $output[] = '<p>Somma totale: <strong>€'.$total.'</strong></p>';
    $output[] = '<div><input type="submit" value="aggiorna carrello" /></div>';
    $output[] = '</form>';
    } else {
    $output[] = '<p>Carrello vuoto.</p>';
    }
    return join('',$output);
    }
    ?> [/PHP]


  • User

    Com'è fatto lo script per l'invio della mail?
    Probabilmente te la devi formattare secondo i tuoi desideri


  • User Newbie

    Ho provato con diversi script tipo questo:
    [PHP]
    require_once('inc/mysql.class.php');
    // Include database connection
    require_once('inc/global.inc.php');
    // Include functions
    require_once('inc/functions.inc.php');
    // Start the session
    session_start();
    // Process actions

    $cart = $_SESSION['cart'];
    $action = $_GET['action'];

    ?>

    <?php
    $to = "mioaccount@diposta";
    $subject = "Ordine ";

    $body = "Ordine:\n\n";
    $body = "tipo: " . trim(stripslashes($total)) . "\r \n";
    $body .= "cart: " . trim(stripslashes($cart)) . "\r \n";
    $body .= "Nome: " . trim(stripslashes($_POST["nomeutente"])) . "\r \n";
    $body .= "Cognome: " . trim(stripslashes($_POST["cognome"])) . "\r \n";
    $body .= "Indirizzo: " . trim(stripslashes($_POST["indirizzo"])) . "\r \n";
    $body .= "Città: " . trim(stripslashes($_POST["citta"])) . "\r \n";
    $body .= "Provincia: " . trim(stripslashes($_POST["provincia"])) . "\r \n";
    $body .= "Telefono: " . trim(stripslashes($_POST["telefono"])) . "\r \n";
    $body .= "E-mail: " . trim(stripslashes($_POST["email"])) . "\r \n";

    $headers = "From: " . trim(stripslashes($_POST["email"])) . "\r \n";
    $headers .= "<" . $_POST["email"] . ">\r\n";
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers .= "Return-Path: " . $_POST["email"];

    if(@mail($to, $subject, $body, $headers))
    {
    echo "La mail contenente i dettagli dell'ordine è stata inoltrata con successo.";
    }
    else
    {
    echo "Si sono verificati dei problemi nell'invio della mail.";
    }
    ?>

    [/PHP]


  • User

    Lo script mi sembra quasi a posto, a questo punto mi sa che non gli stai passando nessun dato tramite la variabile $_POST


  • User Newbie

    il fatto è che non so come fargli entrare il carrello con il post mi servirebbe sapere come mi da solo gli id prodotti


  • User

    Mi sa che è meglio che ti studi come funzionano i form con i relativi metodi.

    Se non ci sbatti un po' la testa e ti prendi solo degli spezzoni di codice in giro per la rete senza capire come e perchè funzionano rischi di non saltarci più fuori.


  • User Newbie

    non so come venirci a capo!!!