Sending array values via email form

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
bukwus
Forum Newbie
Posts: 6
Joined: Thu Dec 17, 2009 2:01 pm

Sending array values via email form

Post by bukwus »

Hi

I've created a form that includes check boxes. Here's a couple examples of the code:

Code: Select all

<input type="checkbox" name="category[]" value="Accounting" /> Accounting<br />
<input type="checkbox" name="category[]" value="Administration" /> Administration<br />
I'm trying to include the checked values of the array "category[]" with the rest of the form's info in an email that results when the form is filled out correctly. Here's the PHP I'm using to handle the email. I've placed ??? where I'm having the trouble:

Code: Select all

$to = 'email@company.org';
$email_subject = 'ExpertNet Aplicant';
$email_body = "Name: ".$_POST['firstName'] . $_POST['lastName']."\n
Title: ".$_POST['title']."\n
Email: ".$_POST['email']."\n
Company: ".$_POST['company']."\n
Company Description: ".$_POST['description']."\n
Address: ".$_POST['address1']."\n
Address: ".$_POST['address2']."\n
City: ".$_POST['city']."\n
State: ".$_POST['state']."\n
Zip Code: ".$_POST['zip']."\n
Phone#: ".$_POST['phone']."\n
Fax#: ".$_POST['fax']."\n
Web Address: ".$_POST['web']."\n
Categories Chosen: "[b][i][u][color=#FF0000]???[/color][/u][/i][/b]" \n
Other: ".$_POST['other'];
$headers = "From:" .$_POST['email'];
 
//Place variables in mail funciton
mail($to, $email_subject, $email_body, $headers);
Hope this makes sense.
Many thanks,
Andy
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sending array values via email form

Post by requinix »

- $_POST["category"] will be an array.
- implode can collapse an array into a string.
Post Reply