Note that there are some explanatory texts on larger screens.

plurals
  1. POEmail a form with multidimensional arrays
    primarykey
    data
    text
    <p>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?</p> <p>Here is the code of the form with the multidimensional array:</p> <pre><code>&lt;form id="form" name="form" method="post" action="send_mail_tray.php" onsubmit='return packageValidator()'&gt; &lt;table width="100%"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="hidden" name="appetizer[]" value="Appetizer 1" /&gt;Appetizer 1&lt;/td&gt; &lt;td style="width: 75px" align="right"&gt; Med: &lt;input type="text" name="appetizer[0][Med]" style="width: 30px" /&gt;&lt;br /&gt; Lg: &lt;input type="text" name="appetizer[0][Lg]" style="width: 30px" /&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="hidden" name="appetizer[]" value="Appetizer 2" /&gt;Appetizer 2&lt;/td&gt; &lt;td style="width: 75px" align="right"&gt; Med: &lt;input type="text" name="appetizer[1][Med]" style="width: 30px" /&gt;&lt;br /&gt; Lg: &lt;input type="text" name="appetizer[1][Lg]" style="width: 30px" /&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="hidden" name="appetizer[]" value="Appetizer 3" /&gt;Appetizer 3&lt;/td&gt; &lt;td style="width: 75px" align="right"&gt; Med: &lt;input type="text" name="appetizer[2][Med]" style="width: 30px" /&gt;&lt;br /&gt; Lg: &lt;input type="text" name="appetizer[2][Lg]" style="width: 30px" /&gt; &lt;/td&gt; &lt;/tr&gt; ... &lt;/table&gt; &lt;input type="Submit" value="Submit Order" /&gt; &lt;/form&gt; </code></pre> <p>My PHP code:</p> <pre><code>foreach ($_POST['appetizer'] as $piece =&gt; $sizes){ $medSize = $sizes['Med']; $lgSize = $sizes['Lg']; if(!empty($medSize) || !empty($lgSize)){ $appetizer .= $_GET['appetizer'] . " - Med: " . $medSize . ", Lg: " . $lgSize; } } $message = ("&lt;p&gt;Thank you for your catering request!&lt;/p&gt; &lt;p&gt;&lt;b&gt;Name:&lt;/b&gt; $name&lt;br /&gt; &lt;b&gt;Phone #:&lt;/b&gt; $phone&lt;br /&gt; &lt;b&gt;Email:&lt;/b&gt; $email&lt;/p&gt; &lt;p&gt;&lt;b&gt;Appetizers:&lt;/b&gt;&lt;br /&gt; $appetizer &lt;/p&gt;"); </code></pre> <p>I have also tried using andrewsi's code but after using it, I no longer receive e-mails:</p> <pre><code>foreach ($_POST['appetizer'] as $piece =&gt; $sizes){ $medSize = $sizes['Med']; $lgSize = $sizes['Lg']; if(!empty($medSize) || !empty($lgSize)){ $message .= $_GET['appetizer'] . " - Med: " . $medSize . ", Lg: " . $lgSize; } } </code></pre> <p>Here is the code for sending the e-mail:</p> <pre><code>$email = $_REQUEST['email']; $mail = new PHPMailer(); $mail-&gt;Host = //SMTP server $mail-&gt;Sender = //Sender $mail-&gt;From = //From $mail-&gt;AddReplyTo("email@email.com"); $mail-&gt;FromName = //FromName; $mail-&gt;AddAddress($email); $mail-&gt;IsHTML(true); $mail-&gt;Subject = //Subject; $mail-&gt;Body=$message; $mail-&gt;WordWrap = 50; $mail-&gt;Send(); echo"&lt;script&gt;window.location='thankyou.html'&lt;/script&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload