PHP Array to email

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Nov 08, 2012 9:30 pm

PHP Array to email

Postby subCutanea » Thu Nov 08, 2012 9:32 pm

So I have an online form that's pretty extensive.
I'm having no issues with dropdowns, radios, text fields and single checkboxes, but a have a large list of options (checkboxes) for clients to check:

<input type="checkbox" name="i_have[]" value="value1" />value1<br />
<input type="checkbox" name="i_have[]" value="value2" />value2<br />
<input type="checkbox" name="i_have[]" value="value3" />value3<br />
<input type="checkbox" name="i_have[]" value="value4" />value4<br />
<input type="checkbox" name="i_have[]" value="value5" />value5<br />
<input type="checkbox" name="i_have[]" value="value6" />value6<br />
...and so on

As you can see, I want this to be an array. I want it emailed to me - everything else emails fine, but this is proving a real problem.
PHP side, I have tried:
Present Issues & Prior Illnesses: $i_haveField
As the responder.

All this does is posts the checked options on the "thanks for signing" page after the client hits the SUBMIT button, but it doesn't send anything in the email.

I have also tried:

if (isset($_POST['i_have'])) {
$i_haveField = $_POST['i_have'];

This is one step closer, printing "ARRAY" in the appropriate area in the email responder, with nothing printed on the "thanks for signing" page, but no checked options are included in the email.

Where am I going wrong?! I know it's something simple, but as a PHP newbie, I just can't see it.

Please could you offer assistance.

User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: PHP Array to email

Postby simplypixie » Thu Nov 08, 2012 11:44 pm

It is very difficult to advise without seeing how you are generating your emails but what you do need to use is a foreach

Code: Select all

foreach ($_POST['i_have'] as $ihave) {
$html .= $ihave;

New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: PHP Array to email

Postby MeroD » Thu Nov 08, 2012 11:56 pm

You can also use the implode() function to join them in a comma separated string:

$checked = trim(stripslashes(implode(",", $_POST['i_have'])));

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests