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

  • Home
  • SEARCH
  • 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 8437945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:34:23+00:00 2026-06-10T07:34:23+00:00

I created a form with a multidimensional arrays and I’m trying to send an

  • 0

I created a form with a multidimensional arrays and I’m trying to send an e-mail with the arrays using PHPmailer by writing the contents of the arrays to a text file and then having it read the file for contents but when I send the e-mail it only shows up as “‘; } fclose(); ?> “. What am I doing wrong?

Here is the code of the form with the multidimensional array:

<form id="form" name="form" method="post" action="send_mail_tray.php" onsubmit='return packageValidator()'>
   <table width="100%">
      <tr>
        <td><input type="hidden" name="appetizer[]" value="Appetizer 1" />Appetizer 1</td>
        <td style="width: 75px" align="right">
            Med: <input type="text" name="appetizer[0][Med]" style="width: 30px" /><br />
            Lg: <input type="text" name="appetizer[0][Lg]" style="width: 30px" />
        </td>
        <td><input type="hidden" name="appetizer[]" value="Appetizer 2" />Appetizer 2</td>
        <td style="width: 75px" align="right">
            Med: <input type="text" name="appetizer[1][Med]" style="width: 30px" /><br />
        Lg: <input type="text" name="appetizer[1][Lg]" style="width: 30px" />
        </td>
        <td><input type="hidden" name="appetizer[]" value="Appetizer 3" />Appetizer 3</td>
        <td style="width: 75px" align="right">
            Med: <input type="text" name="appetizer[2][Med]" style="width: 30px" /><br />
            Lg: <input type="text" name="appetizer[2][Lg]" style="width: 30px" />
        </td>
      </tr>
      ...
   </table>
   <input type="Submit" value="Submit Order" />
</form>

My PHP code:

foreach ($_POST['appetizer'] as $piece => $sizes){
    $medSize = $sizes['Med'];
    $lgSize = $sizes['Lg'];
    if(!empty($medSize) || !empty($lgSize)){
        $appetizer .= $_GET['appetizer'] . " - Med: " . $medSize . ", Lg: " . $lgSize;
    }
}

$message = ("<p>Thank you for your catering request!</p>
    <p><b>Name:</b> $name<br />
    <b>Phone #:</b> $phone<br />
    <b>Email:</b> $email</p>
    <p><b>Appetizers:</b><br />
    $appetizer
    </p>");

I have also tried using andrewsi’s code but after using it, I no longer receive e-mails:

foreach ($_POST['appetizer'] as $piece => $sizes){
    $medSize = $sizes['Med'];
    $lgSize = $sizes['Lg'];
    if(!empty($medSize) || !empty($lgSize)){
        $message .= $_GET['appetizer'] . " - Med: " . $medSize . ", Lg: " . $lgSize;
    }
}

Here is the code for sending the e-mail:

$email = $_REQUEST['email'];
$mail = new PHPMailer();
$mail->Host = //SMTP server
$mail->Sender = //Sender
$mail->From = //From
$mail->AddReplyTo("email@email.com");
$mail->FromName = //FromName;
$mail->AddAddress($email);
$mail->IsHTML(true);
$mail->Subject = //Subject;
$mail->Body=$message;
$mail->WordWrap = 50;
$mail->Send();
echo"<script>window.location='thankyou.html'</script>";
  • 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-10T07:34:24+00:00Added an answer on June 10, 2026 at 7:34 am

    You need to rejig the last piece of code:

    $message = "<p><b>Appetizers:</b><br />";
    
    $fapp = fopen('appetizers.txt', 'r');
    while(!feof($fapp)){
        $message .= fgets($fapp) . '<br />';
    }
    fclose($fapp);
    

    You’re mixing code in with your email text – this way, you’re separating them out.

    Edited to add:

    You can also generate $message straight from $_POST:

    foreach ($_POST['appetizer'] as $piece => $sizes){
        $medSize = $sizes['Med'];
        $lgSize = $sizes['Lg'];
        if(!empty($medSize) || !empty($lgSize)){
            $message .= $piece . " - Med: " . $medSize . ", Lg: " . $lgSize;
        }
    }
    

    That will save you writing and then reading a file.

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

Sidebar

Related Questions

I'm trying to create a form that contains these multidimensional arrays: <input type=text name=cost[1][desc]>
I am trying to hardwire an on-the-fly created form to send JSON using the
I am trying to using a jquery.validate.unotrusive.js plugin to dynamically created form fields like:
I created a form in CodeIgniter framework that successfully uploads an image using the
I created a form application with 1 button and 1 text box to see
I created a form using Swing in Java. In the form I have used
I'm trying to use a dynamically created form to edit content on a page.
I am trying to pass dynamically created form fields to a php script, and
I have created form using ModelForm but its not saving data into database. views.py
I am trying to fill a livecycle created form with form data from django.

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.