Making mail form that will handle more than one SQL table?

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

Post Reply
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Making mail form that will handle more than one SQL table?

Post by jramaro »

Hi Im trying to have multiple database tables pulled and made into blocks of information to send by email.
sorta like a receipt or invoice that lists each. I can get it to work when i echo a page out.
But not sure how to do this for mail.

Heres what i have

Code: Select all

($user_row['user_id'] is set above here) 

$query= "SELECT *  FROM user_cart_records WHERE user_id = " .  $user_row['user_id'] ;  
$result=mysql_query ($query); // Run the query. 
$num=mysql_num_rows($result); 


// Fetch and print all the records. 
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) { 

$user_id                 =  $_SESSION['user_id']; 

$product_name            =  $row['product_name'];  
$product_id              =  $row['product_id']; 
$quantity                =  $row['quantity']; 

$shipping_type           =  $row['shipping_type']; 
$shipping_price          =  $row['shipping_price']; 

$subtotal                =  $row['subtotal']; 
$total                   =  $row['total']; 
$total_display1          = number_format($total,2); 
$date                    =  $row['date']; 

$today = date("F j, Y, g:i a"); 
$ip = $_SERVER['REMOTE_ADDR']; 

$totalSum+=$total; 
$grand_total = number_format($totalSum,2,'.',','); 



// MAKE DYNAMIC MAIL MESSAGE SECTION -  You've GOT MAIL -- YAY. 

$order_description = 
                   "**************** ITEM **************************" . "\r\n" . 
                   "------------------------------------------------" . "\r\n" . 
                   " Order Details" . "\r\n" .  
                   "------------------------------------------------" . "\r\n" . 
            
  
                   "Product Name: " . $product_name . "\r\n" . 
                   "Product ID: " . $product_id . "\r\n" . 
                   "Quantity: " .  $quantity . "\r\n" . 
                    
                   "Subtotal: " . $subtotal . "\r\n" . 
                   "Shipping Type: " . $shipping_type . "\r\n" . 
                   "Shipping Charges: " . $shipping_price . "\r\n" . 
                   " ++  TOTAL ++ : " . $total  . "\r\n" . "\r\n" . 
          
                   "*************************************************************************" . "\r\n" . "\r\n" . 

// END MAIL - YAY 

} 

} 

?>




and then i add this static section to the top of that

Code: Select all

<?php 
//Calculate Grand Total of all above dynamic product blocks. 

$grand_total_mail = "Grand Total_____________" . $grand_total; 



// User info section of mail. 

$message_userinfo = "all the user info mail form here ..blah blah " 


$to      = 'blah@somethin.com'; 
$from    = 'test_blah@somethin.com'; 
$subject = 'New Order' ; 
$message = $message_userinfo . $order_description . $grand_total_mail; 



// Send the mail // 
$ok1 = @mail($to, $subject, $message); 
?>





See how the variable = $order_description
is only going to overwrite itself leaving only the last block of data displayed. How can i get it to display all in an email?
I can get that same script to work if i just echo them onto a webpage , but not with this because of the single variable used.

Any ideas?
Thank You!
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post by EricS »

Are you trying to send a series of these order blocks in one email? Or send an email for each order?

I think you've not gotten an answer because it's a little unclear what your attempting to do.
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Post by jramaro »

make a block of info for each one . In one email.

Its similar as a 'view cart' webpage where you would echo out all of the past order information.
and its al llisted on one page.

but instead of diplaying to webpage, this will be a mail receipt . after purchase is made.


I know the variable pointing to the block of info is wrong. It ovewrites itself each time , leaving only the last block of info in the email.

So what im asking , is how to make all that information , able to be put as perhaps one $message variable in a mail
Post Reply