PHP - email an array

I simplified my example.

HTML

<form id="form_main" name="form_main" method="post" action="webform.php">

<input type="company" name="company">
<input type="text" name="name">
<label><input type="checkbox" name="system[]" value="system1" />system1</label>
<label><input type="checkbox" name="system[]" value="system2" />system2</label>
<label><input type="checkbox" name="system[]" value="system3" />system3</label>
</p>
<p class="cb_submit">
<input type="submit" name="submit" id="submit" value="Submit" />
</p>

</form>

PHP

<?php

    $company = $_POST['company'];
    $name = $_POST['name'];



    $formcontent = "System: $system";
    $recipient = "[email protected]";
    $mailheader = "From: [email protected]";
    mail($recipient, $subject, $formcontent, $mailheader);

    ?>

use system[] as the checkbox name.

var_dump($_POST); to see the difference between using system vs system[].

Personally, the mail() function has not worked for me on any of my servers in several years. If your web server is not also properly configured as a mail server there is a very high chance the big e-mail services like gmail and yahoo etc will reject the messages you send to them. Use an IMAP account instead and a decent mailing library like PHPMailer. https://github.com/thinsoldier/php-beginner-form

Thanks for your help. Can you explain a bit more how I would include var_dump($_POST); in the code? I edited my example above…

var_dump($_POST); is just a tool for inspecting what is in an array. If you show var_dump($_POST); when the name is system and then try it again when the name is system[] you’ll clearly see and hopefully understand the difference between system and system[]

You might see things better with echo "<pre>"; var_dump($_POST); echo "</pre>";

Sponsor our Newsletter | Privacy Policy | Terms of Service