php mail and arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

php mail and arrays

Post by dimxasnewfrozen »

I have a simple submit form with a few check boxes. I'm storing the results of what's being checked into an Array.

How can I use the mail function to send the results of the array?

Just for a small example, I have:

Code: Select all

 
$mailcontent=
    foreach ($location as $loc)
    {
         echo $loc . "<br/>";
    } .  " Thank you!" ; 
 
mail($toaddress,$subject, $mailcontent);
 
I don't want the array printed of course, but I want the results of the array in the main mail message.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php mail and arrays

Post by jackpf »

I think you want implode().
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: php mail and arrays

Post by dimxasnewfrozen »

That's exactly what I needed. Thank you!

Now, how do I break a line for each one?

I tried implode('\n', $locations);
I also tried implode("<br>" ,$locations);

which just prints out \n and <br>...
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php mail and arrays

Post by jackpf »

Try "\n" instead of '\n'. Notice double quotes.
Post Reply