473,656 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($nam e,$email,$addre ss) {
global $admin_email;
$cart = mail_format_car t();

$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_em ail", "$subject", "$msg", "From: $email \nReply-To:
$email");

}

function mail_format_car t() {

foreach ($_SESSION["cart"] as $key => $session_data) {
list($ses_id) = $session_data;
if(isset($ses_i d)) {
$sel_products = mysql_query("SE LECT * FROM moviedb WHERE id=".$ses_id."" );
$item = mysql_fetch_arr ay($sel_product s);
$title = $item['title'];

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

Apr 1 '06 #1
3 1279
Hi,

mail_format_car t() 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($nam e,$email,$addre ss) {
global $admin_email;
$cart = mail_format_car t();

$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_em ail", "$subject", "$msg", "From: $email \nReply-To:
$email");

}

function mail_format_car t() {

foreach ($_SESSION["cart"] as $key => $session_data) {
list($ses_id) = $session_data;
if(isset($ses_i d)) {
$sel_products = mysql_query("SE LECT * FROM moviedb WHERE id=".$ses_id."" );
$item = mysql_fetch_arr ay($sel_product s);
$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*******@attgl obal.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
1720
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 folder. Can someone tell me what type of content I should put in the email to get around the filter? All my content is so far is a thanks for registering message - and a link for them to confirm their email address.
2
2363
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 http-equiv="Content-Type" content="text/html;
8
1982
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 is... <code> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <title>Online Orientation Quiz</title> <meta http-equiv="Content-Type" content="text/html;
7
3278
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 I believe if it's solved, the remaining stuff is easy... my full program until now is here: http://www.geocities.com/tom4_h4wk/progmail.zip the problem is the segmentation fault when main trys to run leficheiro.c.... the *.c2 files are the...
1
9623
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
1
1774
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, thanks. Design the Array of Expected Events, AEE, required by the interrupt system. Each entry i, 0 <= i < 6, in this array contains three fields, AEE.IIC, AEE.InterruptHandler, AEE.WaitingQueue. These elds are designed such that they can...
5
3361
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 I could better understand the concept, he was trying to convey to me. I ran my own example and it crashed and burn "what a surprise!" : (. I ran the authors example out of the book and quess what, it crashed also, : 0. I ran them both on my...
11
1783
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 the php and its executed very nice The page have php code viewed : http://beachtoursegypt.com/booking-form.htm where after submitting the form the data are sent to the confirmation age where the php script lies there and its not executed
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.