如何将多个复选框值发送到邮件


how to send multiple check box values to mail

我有一个表单,填充的值应该通过mail发送,但我的表单中也有多个复选框值。我该如何发送这些?

这是我的代码:

    <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 = "arundsti@gmail.com";
     $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 <mary@example.com>, Kelly <kelly@example.com>' . "'r'n";
    $headers .= 'From: DiamondShine '.$email . "'r'n";
    //$headers .= 'Cc: birthdayarchive@example.com' . "'r'n";
    //$headers .= 'Bcc: birthdaycheck@example.com' . "'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"; }

    ?>

尝试像这样更改复选框名称

cosmeticscosmetics[]hairdressinghairdressing[]

张贴值后,然后implode复选框值

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

在这里,您将获得逗号分隔的值。

我会在这里看看如何做到这一点。这里有一些代码示例,以及一些可能的处理方法。