Jump to content

How do I get multiple values


Lassie

Recommended Posts

I have an e-cart application and need to email a reciept of purchases.

My email will only send/display the last set of purchases. ie if two items are purchased only the detail of item 2 is sent in the email.

 

The code use a function to retrieve the product info and then I use extract to create variables to be referenced in the email.

Have I gone about this the wrong way?

 

foreach ($cart as $product_id => $qty)
  {
    $book = get_book_details($product_id);
    
  }
  	extract($book);
  	
$to = "$email";
$subj = "test";
$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:- $title  by  $author </p>\n"(Only gives last item)
."</body>\n</html>\n";
$mess = wordwrap($mess,70);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 mail($to,$subj,$mess,$headers);



 

 

 

Link to comment
https://forums.phpfreaks.com/topic/46896-how-do-i-get-multiple-values/
Share on other sites

In order to get multiple book details in your email, you would need to make your $book variable an array and add each book to it as you gathered it's details. Something like:

 

$book = array();
foreach ($cart as $product_id => $qty)
  {
    $book[] = get_book_details($product_id);
    
  }

 

Then you would loop through that array while creating the text for your email. Something like:

 

$book_list = "";
foreach($book as $single_book){
extract($single_book)
$book_list .= $title." by ".$author\n";
}

 

.. and then add that to your $mess variable:

 

$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:\n"
."$book_list"</p>"
."</body>\n</html>\n";

Many thanks for your help, but I now get a parse error and I cant see why.


$book = array();
 foreach ($cart as $product_id => $qty)
  {
    $book[] = get_book_details($product_id);
    
  }
$book_list ="";
foreach($book as $single_book)
{
	extract($single_book)
	$book_list.=$title." by ".$author\n";/*parse error*/?
}
  	
$to = "$email";
$subj = "test";
$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:-\n"
."$book_list"</p>"
."</body>\n</html>\n";
$mess = wordwrap($mess,70);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 mail($to,$subj,$mess,$headers);

Thanks for that.

I now get these errors:-

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\easyserv\www\e_cart11\cheque_2.php on line 42

 

Parse error: parse error, unexpected T_STRING in c:\easyserv\www\e_cart11\cheque_2.php on line 42

I expect this is the "" not being correct. Is there a rule for this circumstance?

 

Thanks. That cleared that but I now have a parse error in the email. Is it the "" again?

Could you tell me something a out when to use "" or point me to a tutorial?

Many thanks.

$to = "$email";
$subj = "test";
$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:-\n"
[b]."$book_list"</p>"[/b]	."</body>\n</html>\n";/*parse error*/
$mess = wordwrap($mess,70);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 mail($to,$subj,$mess,$headers);

$to = "$email";
$subj = "test";
$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:-\n"
.$book_list."</p></body>\n</html>\n";
$mess = wordwrap($mess,70);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 mail($to,$subj,$mess,$headers);

Thanks> Cured that but now get parse error 'unepected $ on line 78.

$to = "$email";
$subj = "test";
$mess = "<html>\n"
."<head>\n"
."<title>Test Mail</title>\n"
."</head>\n"
."<body>\n"
."This is an html email test<br />\n"
."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n"
."<p>Your purchases were:-\n"
.$book_list."</p></body>\n</html>\n";

$mess = wordwrap($mess,70);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 mail($to,$subj,$mess,$headers);



display_cart($_SESSION['cart'], false, 1);


//empty shopping cart
      session_destroy();
      echo '<div id="cheque">';
      echo '<p>Thank you for shopping with us.</br>  Your order has been placed.</p></div>';
      echo "</br></br>";
      display_button('index.php', 'continue-shopping', 'Continue Shopping'); 
//	  display_button ('pick_up.php','b_buy','Pick Up Purcahse'); 
echo "</br></br>";
do_html_footer();
?>/*parse error unexpected $*/

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.