1

I have a question regarding PHP form. How can I send the text and multiple checkboxes through php via email? Here is the code:

        <form role="form" action="signup.php"
        method="post" id="myform">
          <div class="row opcje">
            <div class="col-md-4">
              <label class="checkbox">
                <input name="checkbox" type="checkbox" checked="true" value="WOMEN">WOMEN</label>
            </div>
            <div class="col-md-4">
              <label class="checkbox">
                <input name="checkbox" type="checkbox" value="MEN" checked="true">MEN</label>
            </div>
            <div class="col-md-4">
              <label class="checkbox">
                <input name="checkbox" type="checkbox" value="KIDS" checked="true">KIDS</label>
            </div>
          </div>
          <div class="form-group">
            <input class="form-control" id="name" placeholder="NAME" type="text" name="name">
          </div>
          <div class="form-group">
            <input class="form-control" id="email" placeholder="E-MAIL" type="email"
            name="email">
          </div>
          <button type="submit" class="btn btn-lg btn-primary">SIGN UP</button>
        </form>

and PHP:

<?php
  $adresdo = "info@takelake.com";
  $temat = "Newsletter signup";
  $zawartosc = "Imie: ".$_POST['name']."\n"
               ."Email: ".$_POST['email']."\n";

  if(!$_POST['name'] || !$_POST['email']){
     header("Location: error.html");
     exit;
  }
  $email = $_POST['email'];
  if(mail($adresdo, $temat, $zawartosc, 'From: Subskrybent <'.$email.'>')){
  header("Location: ok.html"); 
  }
?>

How can I include checkboxes in the form? Thanks

Piotr Ciszewski
  • 1,691
  • 4
  • 30
  • 53
  • 1
    Possible duplicate of: http://stackoverflow.com/questions/4554758/how-to-read-if-a-checkbox-is-checked-in-php – Mazz Apr 14 '17 at 09:27
  • 1
    Change `name="checkbox"` to `name="checkbox[]"`. – node_modules Apr 14 '17 at 09:30
  • Possible duplicate of [How to read if a checkbox is checked in PHP?](http://stackoverflow.com/questions/4554758/how-to-read-if-a-checkbox-is-checked-in-php) – jediz Apr 14 '17 at 09:39

1 Answers1

2

html

  <form role="form" action="signup.php"
    method="post" id="myform">
      <div class="row opcje">
        <div class="col-md-4">
          <label class="checkbox">
            <input name="checkbox[]" type="checkbox" checked="true" value="WOMEN">WOMEN</label>
        </div>
        <div class="col-md-4">
          <label class="checkbox">
            <input name="checkbox[]" type="checkbox" value="MEN" checked="true">MEN</label>
        </div>
        <div class="col-md-4">
          <label class="checkbox">
            <input name="checkbox[]" type="checkbox" value="KIDS" checked="true">KIDS</label>
        </div>
      </div>
      <div class="form-group">
        <input class="form-control" id="name" placeholder="NAME" type="text" name="name">
      </div>
      <div class="form-group">
        <input class="form-control" id="email" placeholder="E-MAIL" type="email"
        name="email">
      </div>
      <button type="submit" class="btn btn-lg btn-primary">SIGN UP</button>
    </form>

php

<?php
 $adresdo = "info@takelake.com";
  $temat = "Newsletter signup";
  $zawartosc = "Imie: ".$_POST['name']."\n"
           ."Email: ".$_POST['email']."\n"
           ."Selected".implode($_POST['checkbox'],",");

      if(!$_POST['name'] || !$_POST['email']){
         header("Location: error.html");
       exit;
    }
    $email = $_POST['email'];
    if(mail($adresdo, $temat, $zawartosc, 'From: Subskrybent <'.$email.'>'))
    {
       header("Location: ok.html"); 
    }
    ?>
Suresh Suthar
  • 794
  • 8
  • 15
  • thanks, but how to include it in the php? Can I then check all 3 checkboxes in the same time? Can you please modify my php code? – Piotr Ciszewski Apr 14 '17 at 09:30
  • if u need one value at same time then use radio button – Suresh Suthar Apr 14 '17 at 09:33
  • I need to be able to check all 3 too. – Piotr Ciszewski Apr 14 '17 at 09:34
  • I'm not very good in php. Can you paste the whole php which I should replace mine with, please? I need to be able to select 1, 2 or all 3 checkboxes depending on my needs. It's about my interests: am I interested in Men / Women / Kids fashion. I can be interested in few of them, therefore I used checkboxes instead of radio. – Piotr Ciszewski Apr 14 '17 at 09:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141709/discussion-between-suresh-suthar-and-piotr-ciszewski). – Suresh Suthar Apr 14 '17 at 09:46
  • @PiotrCiszewski and let me know which type of need ito get value of checkbox, ex: suppose if u choose men and women then. then u get output liken "men, Women" – Suresh Suthar Apr 14 '17 at 09:48
  • Welcome @PiotrCiszewski – Suresh Suthar Apr 14 '17 at 11:04