Jump to content

passing function output to form/emailing form


vassili

Recommended Posts

hi all,  im running into a roadblock that i can't seem to get past.

 

my problem is 2 fold. i have this function showItems().  it basically spits out an array of the results of what users have added to their shopping cart. 

 

function showItems() {
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[] = '<table align="center" cellpadding="0" border="0">';
	$output[] = '<tr><td>';
	$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
	$output[] = '<table align="center" cellpadding="10" width="820" border="0">';
	foreach ($contents as $id=>$qty) {
		$sql = "SELECT * FROM item WHERE uniq_ID='$id'";
		$result = $db->query($sql);
		$row = $result->fetch();
		extract($row);
		$output[] = '<tr>';
		$output[] = '<td style="border:1px solid #999;"><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
		$output[] = '<td width="400" style="border:1px solid #999;">'.$name.' in '.$color.'</td>';
		$output[] = '<td style="border:1px solid #999;">$'.$price.'</td>';
		$output[] = '<td width="50" style="border:1px solid #999;"><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
		$output[] = '<td style="border:1px solid #999;">$' . number_format($price * $qty, 2) . '</td>';

		$total += $price * $qty;
		$output[] = '</tr>';
	}
	$output[] = '</table>';

	$output[] = '<p align="right">Subtotal: <strong>$'. number_format($total,2).'</strong></p>';
	$output[] = '<div align="right"><button type="submit" id="mysubmit">Update cart</button></div>';
	$output[] = '<p align="right"><a href="memberindex.php" >Back to Shopping...</a></p>
';
	$output[] = '</form>';
} else {
	$output[] = '<p>Your cart is empty.</p>';
}

	$output[] = '</td></tr>';
	$output[] = '</table>';
 	return join('',$output);	 	
}

 

on another page (cart.php), i echo this function to display the results in cart.php.  i also have a form on that page that requires the user to input personal info and then when he/she hits submit, i want everything (results of showItems() + information from the form) passed to submit.php where the code will group them together and send me an email. 

 

submit.php right now has test code that can send the information from the form to me. 

 

if(isset($_POST['submit'])) { 
$to = "me@gmail.com"; 
$subject = "order"; 
$name_field = $_POST['Name']; 
$email_field = $_POST['Email']; 
$message = $_POST['City']; 
  
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; 
  
echo "Data has been submitted to $to!"; 
mail($to, $subject, $body); 
} else { 
echo "failed"; 
} 

 

i just don't know how to work int he showItems() results.  also, sending the email is ok when i run from the actual host server online, but when i try to run it on a localhost through wampserver running windows XP, i get this error.

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing

 

my php.ini looks like this

 

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25


; For Win32 only.
sendmail_from = me@localhost.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

 

phew...that was a mouthful, hopefully someone here understand what i need.  thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.