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

时间:2021-10-17 22:15:00

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 = "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"; }


    ?>

2 个解决方案

#1


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.

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

#2


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.

我想看看如何做到这一点。有一些代码示例,以及一些可能的方法来处理这个问题。

#1


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.

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

#2


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.

我想看看如何做到这一点。有一些代码示例,以及一些可能的方法来处理这个问题。