473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Please, need help with a mail function

bassically i am buiding a simple shopping cart type feature and am using
sessions to store the cart contents and then when teh user checks out and
submits the order it will email me the cart contents.. however right now im
having a problem with it sending the proper data.. Insead of inserting each
item in the cart in teh msg o fthe email it only inserts one item... Below
are the two main functions i am using to accomplish this...I have also tried
it with the return $title; within the foreach loop as well the only thing
that came close was when i had echo $title; within the foreach loop,
unfortunately all this did was upon submitting print the cart contents to
the screen and totally leave them out of the boday of the email... I hope
all that makes sense

=================
function mail_order($name,$email,$address) {
global $admin_email;
$cart = mail_format_cart();

$subject = "DVD ORDER FOR $name";

$msg = "Order Details\n\n"
."$cart\n\n"
."-----------------------------------------------------------------\n"
."Name: $name\n"
."Email: $email\n\n"
."Address:\n"
."$address\n"
."\n\n";
mail("$admin_email", "$subject", "$msg", "From: $email \nReply-To:
$email");

}

function mail_format_cart() {

foreach ($_SESSION["cart"] as $key => $session_data) {
list($ses_id) = $session_data;
if(isset($ses_id)) {
$sel_products = mysql_query("SELECT * FROM moviedb WHERE id=".$ses_id."");
$item = mysql_fetch_array($sel_products);
$title = $item['title'];

}
}
return $title;
}
=======================================

Apr 1 '06 #1
3 1267
Hi,

mail_format_cart() function is returning $title, which is basically
giving you only one item right? Well the way function is executed it
will return the last index of the array $_SESSION['cart']. WHY? Because
in your foreach() you are running query, fetching data and assigning
$item['title'] to $title. So what is basically happening here is as
follows:

+ Starts Loop Cycle 1
+ $title is assigned with first value found in $item['title'], e.g.
Item One
+ Starts Loop Cycle 2
+ $title is assigned AGAIN with the second value found in
$item['title'], e.g. Item Two
.....
+ Start the Last Loop Cycle
+ $title is assigned with the LAST value found in $item['title'],
e.g. ITEM LAST

So returning $title from the function will give your mail ITEM LAST
only. If you write a code like:

$a = "My";
....some more code
$a = "Your";
....some more code
$a = "Our";

echo $a will give us Our. Not My nor Your.

How to get the proper list of items? You can simply make $title an
array to assign values to it. That is, rather than writing $title =
$item['title']; you write:

$title[] = $item['title'];

If you do the above then you will have to run another foreach loop in
mail_order() function. To avoid this you can do this instead, which I
think is very good. Don't even assign it to an array as mentioned
above. Try writing:

$title .= $item['title'] . "\n\n";

Hope this will help. Sorry for the long and big explanation. Thought it
will help.

Thanks and God Bless!!

Ehsan
http://ehsan.bdwebwork.com

Apr 1 '06 #2
Chris H wrote:
bassically i am buiding a simple shopping cart type feature and am using
sessions to store the cart contents and then when teh user checks out and
submits the order it will email me the cart contents.. however right now im
having a problem with it sending the proper data.. Insead of inserting each
item in the cart in teh msg o fthe email it only inserts one item... Below
are the two main functions i am using to accomplish this...I have also tried
it with the return $title; within the foreach loop as well the only thing
that came close was when i had echo $title; within the foreach loop,
unfortunately all this did was upon submitting print the cart contents to
the screen and totally leave them out of the boday of the email... I hope
all that makes sense

=================
function mail_order($name,$email,$address) {
global $admin_email;
$cart = mail_format_cart();

$subject = "DVD ORDER FOR $name";

$msg = "Order Details\n\n"
."$cart\n\n"
."-----------------------------------------------------------------\n"
."Name: $name\n"
."Email: $email\n\n"
."Address:\n"
."$address\n"
."\n\n";
mail("$admin_email", "$subject", "$msg", "From: $email \nReply-To:
$email");

}

function mail_format_cart() {

foreach ($_SESSION["cart"] as $key => $session_data) {
list($ses_id) = $session_data;
if(isset($ses_id)) {
$sel_products = mysql_query("SELECT * FROM moviedb WHERE id=".$ses_id."");
$item = mysql_fetch_array($sel_products);
$title = $item['title'];

}
}
return $title;
}
=======================================


Since I have no idea what's in your $_SESSION variable, I have no idea what
might be wrong with your code.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 1 '06 #3
Why it shows All 4 messages in topic? I see only 3 messages but it says
4???? This one is 4th but dont know how many it will show after post.
Lets see!!

Apr 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jack Smash | last post by:
I am having lots of trouble with the mail function! I simply send a confirmation email to someone who has registered on my site - but thte message usually gets filtered or sent to the bulk mail...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
8
by: shandain | last post by:
Ok, I have done this a million times, and I can't get this to work... I hope I am just being an idiot and missing something... but I can't see it... so please call me an idiot and tell me what it...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: albert_reade | last post by:
Hello I was wondering if someone could please help me understand what I need to do in order to get this project to work. I just need some hints or a push in the right direction to get this to work,...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
11
by: shror | last post by:
Hi every body, Please I need your help solving my php mail() function problem that the code is appearing in the view source and I dont know whats the problem where I am using another page tto test...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.