Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:24:32+00:00 2026-06-17T07:24:32+00:00

I have two separate arrays in my PHP mail form that are different sets

  • 0

I have two separate arrays in my PHP mail form that are different sets of checkboxes: webdetails and graphicdetails. Only one set will be filled out (the other will be hidden unless a previous radio button is selected.) I’m wondering how to reference them correctly in my PHP.

This is what I used to get one to post, but not two:

foreach($_POST['webdetails'] as $value1) {
    $webdetails_msg .= "$value1\n";
}

How do I add graphicdetails in there? Duplicating the snippet gives me Warning: Invalid argument supplied for foreach()

I don’t know much more PHP than this, so an explanation would be appreciated.

—

Here’s the PHP I get an error with:

<?php
/* Set mail headers */
$myemail  = "my.email@gmail.com";
$subject    = "New Request";

$webdetails         = $_POST['webdetails'];
$graphicdetails     = $_POST['graphicdetails'];

foreach($_POST['webdetails'] as $value1) {
    $webdetails_msg .= "$value1\n";
}
foreach($_POST['graphicdetails'] as $value2) {
    $graphicdetails_msg .= "$value2\n";
}

/* Let's prepare the message for the e-mail */
$message = "
Details:
$webdetails_msg
$graphicdetails_msg
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

<?php exit(); } ?>

HTML for webdetails:

<input type="checkbox" name="webdetails[ ]" id="design" value="Design" />
<input type="checkbox" name="webdetails[ ]" id="development" value="Development" />
<input type="checkbox" name="webdetails[ ]" id="web-updates" value="Web Updates" />
<input type="checkbox" name="webdetails[ ]" id="forum-template" value="Forum Template (Full)" />
<input type="checkbox" name="webdetails[ ]" id="forum-graphics" value="Forum Graphics" />
<input type="checkbox" name="webdetails[ ]" id="web-other" value="Other" />

HTML for graphicdetails:

<input type="checkbox" name="graphicdetails[ ]" id="graphic-logo" value="Logo Design" />
<input type="checkbox" name="graphicdetails[ ]" id="graphic-social" value="Social Media Graphics" />
<input type="checkbox" name="graphicdetails[ ]" id="graphic-other" value="Other" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:24:33+00:00Added an answer on June 17, 2026 at 7:24 am

    It looks fine so I am guessing it’s this:

    Checkboxes don’t get posted if they are not checked, you need to check there are any

    if (isset($_POST['graphicdetails'])){
        foreach($_POST['graphicdetails'] as $value1) {
            $webdetails_msg .= "$value1\n";
        }
    }
    

    But in any case

    if (isset($_POST['graphicdetails'])){
        $webdetails_msg .= implode("\n", $_POST['graphicdetails'])."\n";
    } // you don't need the curly braces for 1 line but SO has a small code width
    

    is less to write

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two separate sets of tables in the same database that model the
I have two separate applications (both part of the same system) that share a
I have two separate caches running in a JVM (one controlled by a third
We have two databases, in two separate locations. One of the databases resides in
i just have a php array with number that i've explode to separate itens,
I have the following code which grabs two separate arrays, flips the surname and
I just ran into something weird. I have two JSON arrays which holds different
I have two separate arrays - $array_before and $array_after . Each array can have
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
Say I have two separate classes, A and B. I also have Repository class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.