Emailing cart contents to customer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

here's a guess.. remove the ******* bits.
squatchimo
Forum Commoner
Posts: 28
Joined: Thu Feb 03, 2005 3:36 pm

Re: Emailing cart contents to customer

Post by squatchimo »

I tried that also but still no query results. Here is my modified code:

Code: Select all

} else {

$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracking 
as tr left join inventory as inv on inv.id = tr.item_id where session_id = '$userses'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
		
    $subject = "blah blah blah...";

    $message = "Dear $firstname $lastname, 
    Thank you for ordering at blah.com! 

	Order Summary:\n";
	while ($cart = mysql_fetch_array($get_cart_res)) {
   	$name = stripslashes($cart['name']);
   	$price = $cart['price'];
   	$qty = $cart['qty'];
    $message .= "$qty";
    }
	$message .= "Subtotal: $subtotal
	Tax: $tax
	Shipping: $shipping
	Total: $total
	
	Blah blah blah...";

mail($email, $subject, $message, "From: blah@blah..com\r\n");
header("Location: https://-URL-");
}
Again, everything in $message comes through EXCEPT for what is in the query. But the query IS good and DOES return results if I simply echo it. I've also tried substituting the $userses value with a hard number just to be sure it wouldn't interfere.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please post the code where you put the echo in and it worked.

I am completely mystified by this :?

I assume when you say the query works, you tested it from within this exact same script... that's vital.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

can you post the full source of this email? I'm having a hard time visualizing what is and isn't showing.. Also, a var_export() of $message just before you send the email would be helpful as well.

Full source of an email includes all headers the email had, as well as the content involved.
squatchimo
Forum Commoner
Posts: 28
Joined: Thu Feb 03, 2005 3:36 pm

Post by squatchimo »

Here is the entire submit page:

Code: Select all

<?php
session_start();
header("Cache-control: private");/* IE6 fix */
include('../phpcode/include.php');

$cc_type = $_POST['cc_type'];
$cc_number = $_POST['cc_number'];
$cc_month = $_POST['cc_month'];
$cc_year = $_POST['cc_year'];
$cc_holder = $_POST['cc_holder'];

$cc_type = stripslashes($cc_type);
$cc_number = stripslashes($cc_number);
$cc_month = stripslashes($cc_month); 
$cc_year = stripslashes($cc_year); 
$cc_holder = stripslashes($cc_holder);

if((!$cc_type) || (!$cc_number) || (!$cc_month) || (!$cc_year) || (!$cc_holder)) { 
    echo 'You did not submit the following information: <br />'; 
    if(!$cc_type){ 
        echo "Credit card type is a required field. Please enter it below.<br />"; 
    }
    if(!$cc_number){ 
        echo "Credit card number is a required field. Please enter it below.<br />"; 
    }
    if(!$cc_month){ 
        echo "Card expiration month is a required field. Please enter it below.<br />"; 
    } 
    if(!$cc_year){ 
        echo "Card expiration year is a required field. Please enter it below.<br />"; 
    } 
    if(!$cc_holder){ 
        echo "Cardholder name is a required field. Please enter it below.<br />"; 
    }

    include 'payment_info.php';
    exit();
}

// Assign variables from sessions:
$sesid = $_SESSION["usersession"];
$firstname = $_SESSION["firstnamex"];
$lastname = $_SESSION["lastnamex"];
$email = $_SESSION["emailx"];
$address1 = $_SESSION["address1x"];
$address2 = $_SESSION["address2x"];
$city = $_SESSION["cityx"];
$state = $_SESSION["statex"];
$zip = $_SESSION["zipx"];
$phone = $_SESSION["phonex"];
$subtotal = $_SESSION["subtotalx"];
$tax = $_SESSION["taxx"];
$shipping = $_SESSION["shippingx"];
$total = $_SESSION["totalx"];

// Enter info into the Database.
$query = "INSERT INTO orders (order_date,order_firstname,order_lastname,order_address1,
order_address2,order_city,order_state,order_zip,order_tel,order_email,item_total,
shipping_total,status,tax,total,session_id,cc_type,cc_number,cc_month,cc_year,cc_holder) 
VALUES (localtime(),'$firstname','$lastname','$address1','$address2','$city','$state',
'$zip','$phone','$email','$subtotal','$shipping','','$tax','$total','$sesid','$cc_type',
'$cc_number','$cc_month','$cc_year','$cc_holder')";
$result = mysql_query($query);
echo mysql_error();

if(!$result){ 
    echo 'Query error!'; 
} else {
// Get cart contents:
$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracker 
as tr left join inventory as inv on inv.id = tr.item_id where session_id = '$userses'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
		
    $subject = "Your Order at blah.com!";
    $message = "Dear $firstname $lastname, 
    Thank you for ordering at http://www.blah.com! 

	Order Summary:\n";
	while ($cart = mysql_fetch_array($get_cart_res)) {
   	$name = stripslashes($cart['name']);
   	$price = $cart['price'];
   	$qty = $cart['qty'];
    $message .= "$qty";
    }
	$message .= "Subtotal: $subtotal
	Tax (Florida Residents Only): $tax
	Shipping: $shipping
	Total: $total
	
	Thanks for the order...blahblahblah..."; 

mail($email, $subject, $message, "From: orders@blah.com\r\n");
header("Location: https://URL/logoff.php");
} 
?>
When I receive the email, it reads as follows:

Code: Select all

&quote;Dear John Doe, 
Thank you for ordering at http://www.blah.com! 

Order Summary:
Subtotal: 1000
Tax (Florida Residents Only): 70.00
Shipping: 10.00
Total: 1080.00

Thanks for the order...blahblahblah...&quote;
The email headers are:

Code: Select all

Return-Path: &lt;orders@blah.com&gt;

Received: from blah.com (blah.com &#1111;xxx.xxx.xxx.xxx])

            by routing.blah.com (8.11.6/8.11.6) with ESMTP id j2BFL5cxxxxx

            for &lt;johndoe@customer.com&gt;; Fri, 11 Mar 2005 09:21:08 -0600

Received: (from blah@localhost)

            by blah.com (8.11.6/8.11.6) id j2BFKvcxxxxx;

            Fri, 11 Mar 2005 09:20:57 -0600

Date: Fri, 11 Mar 2005 09:20:57 -0600

Message-Id: &lt;200503111520.j2BFKvcxxxxx@blah.com&gt;

To: johndoe@customer.com

Subject: Your Order at blah.com!

From: orders@blah.com

X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on 

            blah.com

X-Spam-Status: No, hits=0.3 required=99.0 tests=NO_REAL_NAME autolearn=no 

            version=2.63

X-Spam-Level: 

Status:
After the page is submitted, the data inserted from the form goes into the orders table successfully and the email is sent.


feyd | :grumble-grumble:
Last edited by squatchimo on Fri Mar 11, 2005 11:35 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it still looks like it never enters the query loop..
squatchimo
Forum Commoner
Posts: 28
Joined: Thu Feb 03, 2005 3:36 pm

Post by squatchimo »

squatchimo wrote:OK, to test that thought, I modified the code to echo one of the results:

Code: Select all

$num = 160;
$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracker 
as tr left join inventory as inv on inv.id = tr.item_id where tr.id = '$num'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
	while ($cart = mysql_fetch_array($get_cart_res)) {
   	$name = stripslashes($cart['name']);
   	$price = $cart['price'];
   	$qty = $cart['qty'];
    $message .= "$qty. x .$name. - £.$price. each\n";
    }
	
echo $name;
And the proper name is displayed. So the query does work and does return results. $cart is not empty.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, I'm aware you said that.. it doesn't change the fact that it still appears to never enter the loop.

I'd like to see a live version of this... preferably where I can get it to email me the details and what-not. If you don't want to give out the link publicly, that's fine. PM me the details. If possible, I'd like to get a copy of the code throughout along with database exports so I can play around with it on my server, if need be..
squatchimo
Forum Commoner
Posts: 28
Joined: Thu Feb 03, 2005 3:36 pm

Post by squatchimo »

I came across another post in a different forum that had the same problem but no solution. This is the only thing keeping me from finalizing this project and the client is getting anxious. Anybody have any thoughts? I've gone over it as much as I can.
squatchimo
Forum Commoner
Posts: 28
Joined: Thu Feb 03, 2005 3:36 pm

Post by squatchimo »

I've been searching for a solution to this problem for a few weeks now and still no luck. Since nobody here can think of a solution either, I've decided to disable this feature for the customer. Order totals will still email to the customer, but not item detail. It's the best I can do.

Thanks to Feyd and everyone who spent time looking at this.
Post Reply