Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: Sending Shopping Cart Info To An Email

  1. #1

    Sending Shopping Cart Info To An Email

    I have a shopping cart that allows you to update edit and remove items however it does not allow you to send the data. I want a button that says "Submit Your Order" and an email is sent with the order info, but I'm not sure how to accomplish this.

    here is the "function.inc.php" files.

    PHP Code:
    <?php
    function writeShoppingCart() {
        
    $cart $_SESSION['cart'];
        if (!
    $cart) {
            return 
    '<p>You have no items in your shopping cart</p>';
        } else {
            
    // Parse the cart session variable
            
    $items explode(',',$cart);
            
    $s = (count($items) > 1) ? 's':'';
            return 
    '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</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;
            }
            
    $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
            
    $output[] = '<table width=700>';
            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 width=60><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
                
    $output[] = '<td width="30"> Date: '.$row['date'].'</td>';
                
    $output[] = '<td><b>Item:</b><br>'.$item.'<br><b>Description:</b><br>'.$description.'</td>';
                
    $output[] = '<td>$'.$price.'</td>';
                
    $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
                
    $output[] = '<td>$'.($price $qty).'</td>';
                
    $total += $price $qty;
                
    $output[] = '</tr>';
            }
            
    $output[] = '</table>';
            
    $output[] = '<p>Grand total: <strong>$'.$total.'</strong></p>';
            
    $output[] = '<div><button type="submit">Update cart</button></div>';
            
    $output[] = '</form>';
        } else {
            
    $output[] = '<p>You shopping cart is empty.</p>';
        }
        return 
    join('',$output);
    }
    ?>

  2. #2
    Just use the mail() PHP function to send the email. You already have the body of the email from writeShoppingCart() function

    sample code:
    PHP Form to email

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012