Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-06-2004, 02:02 PM
|
#1
|
Member
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Rep:
|
PHP Mail and Foreach function
Hi Guys. I recently finished my session cart but I have a couple of questions:
When I want to display the cart items I do:
PHP Code:
$items = $cart->get_contents(); foreach($items as $item) { echo "Code/ID :".$item['id']."<br>"; echo "Quantity:".$item['qty']."<br>"; echo "Price :".$item['price']."<br>"; echo "Info :".$item['info']."<br>"; echo "Subtotal".$item['subtotal']."<br>"; }
But now I would like to send all the items of the cart by email, but I dont know how can I assign all the above function to a variable and send it as:
PHP Code:
mail($email, 'Subject' $alltheitems, "From: $email\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion());
Or how can you suggest me to send all the items via email?
I will appreciate some help.
Thanks a lot.
|
|
|
10-06-2004, 02:27 PM
|
#2
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
Re: PHP Mail and Foreach function
Something like this worked for me:
PHP Code:
$items = $cart->get_contents(); foreach($items as $item) { $alltheitems = "Code/ID : ".$item['id'] ."\n"; $alltheitems .= "Quantity: ".$item['qty'] ."\n"; $alltheitems .= "Price : ".$item['price'] ."\n"; $alltheitems .= "Info : ".$item['info'] ."\n"; $alltheitems .= "Subtotal: ".$item['subtotal'] ."\n"; } $email = "you@localhost"; // dummy example address $from = "shop@localhost"; // dummy example address mail( $email, "Your order", $alltheitems, "From: $from\r\n". "X-Mailer: PHP/" . phpversion() );
Last edited by Hko; 10-06-2004 at 02:31 PM.
|
|
|
10-06-2004, 02:59 PM
|
#3
|
Member
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Original Poster
Rep:
|
Thanks Hko. I have another question. Do I need to decare $alltheitems inside the loop or outside?, cause I tried and it works fine but just send the last request item on the cart.
PD: what does .= do?
Thanks in advance..
|
|
|
10-06-2004, 03:06 PM
|
#4
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
Quote:
Originally posted by Gerardoj
Do I need to decare $alltheitems inside the loop or outside?, cause I tried and it works fine but just send the last request item on the cart.
|
Hmm, I did try the script and for me it sent all the lines.
In PHP you don't need to declare a variable, just assign it a value.
I appends a string to a string variable.
PHP Code:
$strvar .= "some text";
does the same thing as:
PHP Code:
$strvar = $strvar . "some text";
Note that in the loop I posted, the first time $alltheitems is assigned a string it does not have the dot ( . ).
Did you actually use the dots as in " .=" when you tried my script?
If not, that would explain why you get only the last item...
Last edited by Hko; 10-06-2004 at 03:11 PM.
|
|
|
10-06-2004, 05:46 PM
|
#5
|
Member
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Original Poster
Rep:
|
Thanks lot Hko. now Its working fine.
I just changed it for:
PHP Code:
$alltheitems=""; foreach($items as $item) { $alltheitems .= "Code/ID : ".$item['id'] ."\n"; $alltheitems .= "Quantity: ".$item['qty'] ."\n"; $alltheitems .= "Price : ".$item['price'] ."\n"; $alltheitems .= "Info : ".$item['info'] ."\n"; $alltheitems .= "Subtotal: ".$item['subtotal'] ."\n"; }
Thanks again
|
|
|
10-07-2004, 05:50 AM
|
#6
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
Quote:
Originally posted by Gerardoj
I just changed it for:
PHP Code:
$alltheitems=""; foreach($items as $item) { // [..snip..]
|
That looks OK.
Didn't it work without initializing before the loop? ($alltheitems="";)
(just wondering)
Last edited by Hko; 10-07-2004 at 06:09 AM.
|
|
|
10-08-2004, 05:24 PM
|
#7
|
Member
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Original Poster
Rep:
|
I tried but It didnt worked me.. Maybe I did it wrong...
But thanks again...
Regards....
|
|
|
All times are GMT -5. The time now is 04:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|