Lassie Posted April 13, 2007 Share Posted April 13, 2007 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); Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 13, 2007 Share Posted April 13, 2007 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"; Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 14, 2007 Author Share Posted April 14, 2007 Thanks I will try that. Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 14, 2007 Author Share Posted April 14, 2007 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); Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 Missing semicolon after extract($single_book) (the line before your comment) Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 15, 2007 Author Share Posted April 15, 2007 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? Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 15, 2007 Share Posted April 15, 2007 Typo my part (sorry I was in a hurry while I wrote the code). Change: $book_list.=$title." by ".$author\n"; ... to ... $book_list.=$title." by ".$author."\n"; Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 16, 2007 Author Share Posted April 16, 2007 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); Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 16, 2007 Share Posted April 16, 2007 $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); Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 16, 2007 Author Share Posted April 16, 2007 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 $*/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.