Order Form

Hi there. I was just setting up an order form and the instructions were to add in my email address and then uncomment the “mail” function to send the emails. I’m just a bit lost with this. Can somebody please take a look? Thanks in advance.

The original form came from here: http://www.dyn-web.com/code/order_form/example2.php
My form is here: http://www.theoxfordbathurst.com.au/onlineorder/example2.php
My code is below.

[php]<?php
require(‘includes/ex2.inc.php’);

function sendAdminEmail($total, $order) {
$admin_email = ‘[email protected]’;
$subject = ‘Order Information’;
$name = stripslashes( strip_tags( $_POST[‘first_name’] ) ) . ’ ’ .
stripslashes( strip_tags( $_POST[‘last_name’] ) );

$email = stripslashes( strip_tags( $_POST['email'] ) );
// check for valid email address
$regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-zA-Z]{2,}$/';
if ( !preg_match($regex, $_POST['email']) ) {
    // don't send email
    echo '<p>Your email appears to be invalid. Please hit your browser back button to return to the previous page to enter a vaild email address.</p>';
    return;
}
$phone = stripslashes( strip_tags( $_POST['phone'] ) );
$msg_body = "Order placed for: 
$order 

Total: $$total

Name: $name
Email: $email
Phone: $phone";

//echo nl2br($msg_body); // for testing

//@mail($admin_email, $subject, $msg_body );

}

function handleOrderInfo() {
global $PRODUCTS;;
$str = ‘’; $total = 0; $order = ‘’;
while ( list($key, $val) = each($_POST) ) {
// Check for valid quantity entries > 0
if ( ( strpos($key, ‘_qty’) !== false ) && is_int( (int)$val) && $val > 0 ) {
$pt = strrpos($key, ‘_qty’); // get product abbr
$name_pt = substr( $key, 0, $pt);

        foreach($PRODUCTS as $product) {
            list($prod_abbr, $prod_name, $prod_price) = $product;
            if ($prod_abbr == $name_pt) {
                $sub_tot = $val * $prod_price;
                // build string to display order info
                $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                    ' each for $' . number_format($sub_tot, 2) . '</p>';
                $total += $sub_tot;
                $order .= "$val $prod_abbr, ";
            }
        }
    }
}
$total = number_format($total, 2);
$order = rtrim($order, ', ');
if ( $str === '' ) {
    $str = '<p>You didn\'t order anything.</p>';
} else {
    $str = "<h2>Your Order:</h2>$str<p>Total: $$total</p>";
    sendAdminEmail($total, $order);
}

return $str;

}
?>

Your Order <?php echo handleOrderInfo(); ?>

 

A sendAdminEmail function is included in the head of this file. You will need to place your email address there ($admin_email) and uncomment the mail function to send the emails.

Back to index

[/php]

around line 30 in your code change

//@mail($admin_email, $subject, $msg_body );

to

@mail($admin_email, $subject, $msg_body );

the double forward slash // comments that little section of code out where it calls $admin_email.

Also make sure you have correct email address at line 4

Sponsor our Newsletter | Privacy Policy | Terms of Service