0

I have a form, and the filled values are supposed to sent via mail, but I have multiple checkbox values in my form as well. How do I send those as well?

Here is my code:

    <form name="" action="amail.php" method="post" class="wpcf7-form" novalidate>
              <div style="display: none;">
                <input type="hidden" name="_wpcf7" value="219" />
                <input type="hidden" name="_wpcf7_version" value="4.1" />
                <input type="hidden" name="_wpcf7_locale" value="en_US" />
                <input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f219-o1" />
                <input type="hidden" name="_wpnonce" value="70d65de13d" />
              </div>
              <h2>Make a Appointment</h2>
              <p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim.</p>
              <div class="form-field">
                <h5 class="form-field-title">Cosmetics</h5>
                <p><span class="wpcf7-form-control-wrap res-services-1"><span class="wpcf7-form-control wpcf7-checkbox"><span class="wpcf7-list-item first">
                  <label>
                    <input type="checkbox" name="cosmetics" value="Facials" />
                    &nbsp;<span class="wpcf7-list-item-label">Facials</span></label>
                  </span><span class="wpcf7-list-item">
                  <label>
                    <input type="checkbox" name="cosmetics" value="Eyebrow &amp; Eyelashes" />
                    &nbsp;<span class="wpcf7-list-item-label">Eyebrow &amp; Eyelashes</span></label>
                  </span><span class="wpcf7-list-item">
                  <label>
                    <input type="checkbox" name="cosmetics" value="Microdermabrasion" />
                    &nbsp;<span class="wpcf7-list-item-label">Microdermabrasion</span></label>
                  </span><span class="wpcf7-list-item last">
                  <label>
                    <input type="checkbox" name="cosmetics" value="Acne Treatments" />
                    &nbsp;<span class="wpcf7-list-item-label">Acne Treatments</span></label>
                  </span></span></span> </p>
              </div>
              <div class="form-field">
                <h5 class="form-field-title">Hairdressing</h5>
                <p><span class="wpcf7-form-control-wrap res-services-2"><span class="wpcf7-form-control wpcf7-checkbox"><span class="wpcf7-list-item first">
                  <label>
                    <input type="checkbox" name="hairdressing" value="Wash" />
                    &nbsp;<span class="wpcf7-list-item-label">Wash</span></label>
                  </span><span class="wpcf7-list-item">
                  <label>
                    <input type="checkbox" name="hairdressing" value="Cut &amp; Finish" />
                    &nbsp;<span class="wpcf7-list-item-label">Cut &amp; Finish</span></label>
                  </span><span class="wpcf7-list-item">
                  <label>
                    <input type="checkbox" name="hairdressing" value="Blow Dries" />
                    &nbsp;<span class="wpcf7-list-item-label">Blow Dries</span></label>
                  </span><span class="wpcf7-list-item last">
                  <label>
                    <input type="checkbox" name="hairdressing" value="Hair Colouring &amp; Highlights" />
                    &nbsp;<span class="wpcf7-list-item-label">Hair Colouring &amp; Highlights</span></label>
                  </span></span></span> </p>
              </div>
              <hr class="c-divider">
              <div class="wpcf7-response-output wpcf7-display-none"></div>
              <div class="row">
                <div class="col-sm-6">
                  <div class="form-field">
                    <label for="res-your-name">Your Name <span>*</span></label>
                    <span class="wpcf7-form-control-wrap res-your-name">
                    <input type="text" name="name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" id="res-your-name" aria-required="true" aria-invalid="false" />
                    </span></div>
                  <div class="form-field">
                    <label for="res-your-email">Your Email Address</label>
                    <span class="wpcf7-form-control-wrap res-your-email">
                    <input type="email" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-email" id="res-your-email" aria-invalid="false" />
                    </span></div>
                  <div class="form-field">
                    <label for="res-your-phone">Your Phone Number</label>
                    <span class="wpcf7-form-control-wrap res-your-phone">
                    <input type="tel" name="phone" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-tel" id="res-your-phone" aria-invalid="false" />
                    </span></div>
                </div>
                <div class="col-sm-6">
                  <div class="form-field">
                    <label for="res-reservation-date">Preferred Date & Time</label>
                    <div class="row">
                      <div class="col-sm-6">
                        <div class="datepicker-input" data-date-format="mm/dd/yy" data-first-day="0"><span class="wpcf7-form-control-wrap res-reservation-date">
                          <input type="text" name="date" value="" size="40" class="wpcf7-form-control wpcf7-text" id="res-reservation-date" aria-invalid="false" />
                          </span></div>
                      </div>
                      <div class="col-sm-6"> <span class="wpcf7-form-control-wrap res-reservation-time">
                        <select name="time" class="wpcf7-form-control wpcf7-select" aria-invalid="false">
                          <option value="9:00">9:00</option>
                          <option value="9:30">9:30</option>
                          <option value="10:00">10:00</option>
                          <option value="10:30">10:30</option>
                          <option value="11:00">11:00</option>
                          <option value="11:30">11:30</option>
                          <option value="12:00">12:00</option>
                          <option value="12:30">12:30</option>
                          <option value="13:00">13:00</option>
                          <option value="13:30">13:30</option>
                          <option value="14:00">14:00</option>
                          <option value="14:30">14:30</option>
                          <option value="15:00">15:00</option>
                        </select>
                        </span> </div>
                    </div>
                  </div>
                  <div class="form-field">
                    <label for="res-reservation-note">Note</label>
                    <span class="wpcf7-form-control-wrap res-reservation-note">
                    <textarea name="note" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea" id="res-reservation-note" aria-invalid="false"></textarea>
                    </span></div>
                  <div class="form-field">
                    <input type="submit" value="Send" name="submit" class="wpcf7-form-control wpcf7-submit c-button" />
                  </div>
                </div>
              </div>
            </form>

    amail.php:
    <?php

     $to = "[email protected]";
     $subject = 'A new Appointment Enquiry on DiamondShine';
     $cosmetics=$_REQUEST['cosmetics'];
     $hairdressing=$_REQUEST['hairdressing'];
     $name = $_REQUEST['name'];
      $email = $_REQUEST['email'];
     $phone = $_REQUEST['phone'];
      $date = $_REQUEST['date'];
    $time=$_REQUEST['time'];
     $note=$_REQUEST['note'];





     $message = '<img src=\imagedental\'><br>
     <b>cosmetics</b>: '.$cosmetics.'<br><br><b>hairdressing</b>: '
     .$hairdressing.'<br><br><b>Name</b>: '
     .$name.'<br><br><b>Email</b>: '
     .$email.'<br><br><b>phone</b>: '
     .$phone.'<br><br><b>Date</b>: '
     .$date.'<br><br><b>Time</b>: '
     .$time.'<br><br><b>Note</b>:'.$note;
     // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    //$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
    $headers .= 'From: DiamondShine '.$email . "\r\n";
    //$headers .= 'Cc: [email protected]' . "\r\n";
    //$headers .= 'Bcc: [email protected]' . "\r\n";
     $sent = mail($to, $subject, $message, $headers) ;
     if($sent)
     {
     ?>
    <script type="text/javascript">
    alert('Thanks for contacting Us. We will be in touch with you shortly...');
    location.href = "contactus.php";
    </script>
    <?php
     }
     else
     {print "We encountered an error sending your mail"; }


    ?>

2 Answers 2

0

Try to change your checkbox name like this

cosmetics to cosmetics[] and hairdressing to hairdressing[]

After Post the values then implode the checkbox values

$cosmetics=implode(",",$_REQUEST['cosmetics']);
$hairdressing=implode(",",$_REQUEST['hairdressing']);

Here you will get comma seperated values.

Sign up to request clarification or add additional context in comments.

3 Comments

<input type="checkbox" name="hairdressing[]" value="Wash" /> $cosmetics=implode(",",$_REQUEST['cosmetics']); this is the way u said right...?
Yes. Exactly. @arunkumar
If you satisfied with answer please accept it...Thanks.:)
0

I would have a look here on how to do this. There are some code samples, and some possibles ways you can handle this.

2 Comments

ok....please give me solution.....here i have to combine multiple check box values to $cosmetics,$hairdressing if they selected two values
I cannot help you if you cannot help yourself. I have guided you in the correct direction in order to get the solution you're looking for. If you run into issues, please post back with the problem, and I will try to help you out further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.