treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Need help in getting checkbox results into email body

  • I have a "Get a Quote" form on my website that has multiple checkboxes. I would like a list of the choices to appear in the email that I ultimately receive. Having tried a number of different code solutions I'm still not seeing the checkbox results in the sent emails. I'm sending the code and the html in hopes that forum users will be able to suggest where I'm going wrong. (I will admit that I'm a newbie - so please be gentle - I'm sending all of the code just in case)

    **Here's the pertinent html **

    <?php session_start(); ?> <!DOCTYPE html>

                <form id="quote-form" class="clearfix"       
                   method="post" action="process_quote.php"> 
    
                <label for="services">What services are you interested in? (Check all that apply)</label>
    
    
    
                             <ul class="checkbox">   
                                <li>  
                                <input type="checkbox" name="WebD" value="WebD">    
                                    <label for="WebD">Web Design</label> 
                                </li> 
    
                                <li>   
                                    <input type="checkbox" name="LogoD" value="LogoD" /> 
                                    <label for="LogoD">Logo Design</label>
                                </li> 
    
                                <li>    
                                    <input type="checkbox" name="BCard" value="BCard" />
                                    <label for="BCard">Business Card</label>
                                </li>
    
                                 <li>   
                                    <input type="checkbox" name="Stationery" value="Stationery" />
                                    <label for="Stationery">Corporate Stationery</label>
                                </li>
    
                                <li>    
                                    <input type="checkbox" name="Brochure" value="Brochure" />
                                    <label for="Brochure">Brochure Design</label>
                                </li> 
    
                                <li>      
                                    <input type="checkbox" name="Pcard" value="Pcard"/>
                                    <label for="Pcard">Postcard Design</label>
                                </li>                 
    
                                <li>
                                    <input type="checkbox" name="RCard" value="RCard"/>
                                    <label for="RCard">Rack Card Design</label>
                                </li> 
    
                                <li>    
                                    <input type="checkbox" name="Flyer" value="Flyer" />
                                    <label for="Flyers">Flyers/Sell Sheets</label>
                                </li> 
    
                                <li>    
                                    <input type="checkbox" name="Newsletter" value="Newsletter"/>
                                    <label for="Newsletter">Newsletters</label>
                                </li> 
    
                                <li>
                                    <input type="checkbox" name="Ads" value="Ads"/>
                                    <label for="Ads">Print Ads</label>
                                </li> 
    
                                <li>
                                    <input type="checkbox" name="Other" value=="Other"/>
                                    <label for="Other">Other (Please specify in message area below)</label> 
                                </li>              
    
                            </ul>     
    
    
                        </form>
    
                 <?php unset($_SESSION['cf_returndata']); ?>
    
    </div>
    

    Here's the applicable php:

    <?php
    if( isset($_POST) ){
    
      //form validation vars
    
      $formok = true;
      $errors = array();
    
      //submission data
    
      $ipaddress = $_SERVER['REMOTE_ADDR'];
      $date = date('m/d/Y');
      $time = date('H:i:s');
    
      //form data
    
      $name = $_POST['name']; 
      $email = $_POST['email'];
      $telephone = $_POST['telephone'];
      $company = $_POST['company'];
      $web = $_POST['web'];
      $budget = $_POST['budget'];
    
    
    
    if (isset ($_POST ['WebD'])){   
      $WebD = $_POST ['Web Design']; 
    }   
    else {
      $WebD = ""; 
    }
    
    if (isset ($_POST ['LogoD'])) {   
      $LogoD = $_POST ['Logo Design']; 
    }   
    else {
      $LogoD = ""; 
    }
    
    if (isset ($_POST ['BCard'])){  
      $BCard = $_POST ['Business Card']; 
    }   
    else {
      $BCard = ""; 
    }
    
    if (isset ($_POST ['Stationery'])) {  
      $Stationery = $_POST ['Corporate Stationery']; 
    }   
    else {
      $Stationery = ""; 
    }
    
    if (isset ($_POST ['Brochure'])){   
      $Brochure = $_POST ['Brochure']; 
    }   
    else {
      $Brochure = ""; 
    }
    
    if (isset ($_POST ['Pcard'])) {   
      $Pcard = $_POST ['Postcard']; 
    }   
    else {
      $Pcard = ""; 
    }
    
    if (isset ($_POST ['RCard'])){  
      $RCard = $_POST ['Rack Card']; 
    }   
    else {
      $RCard = ""; 
    }
    
    if (isset ($_POST ['Flyers'])) {  
      $Flyers = $_POST ['Flyers']; 
    }   
    else {
      $Flyers = ""; 
    }
    
    if (isset ($_POST ['Newsletter'])){   
      $Newsletter = $_POST ['Newsletter']; 
    }   
    else {
      $Newsletter = ""; 
    }
    
    if (isset ($_POST ['Ads'])) {   
      $Ads = $_POST ['Print Ads']; 
    }   
    else {
      $Ads = ""; 
    }
    
    if (isset ($_POST ['Other'])) {   
      $Other = $_POST ['Other']; 
    }   
    else {
      $Other = ""; 
    }
    
    
    
      //validate form data
    
      //validate name is not empty
    
      if(empty($name)){
        $formok = false;
        $errors[] = "We need your name";
      }
    
      //validate email address is not empty
    
      if(empty($email)){
        $formok = false;
        $errors[] = "Please enter an email address";
    
      //validate email address is valid
    
      }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        $formok = false;
        $errors[] = "You have not entered a valid email address";
      }
    
    
      //send email if all is ok
    
      if($formok){
        $headers = "From: quote@modsnapdesign.com" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
        $emailbody = "<p>You have recieved a quote request.</p>
                <p><strong>Name: </strong> {$name} </p>
                <p><strong>Email Address: </strong> {$email} </p>
                <p><strong>Telephone: </strong> {$telephone} </p>
                <p><strong>Company Name: </strong> {$company} </p>
                <p><strong>Website: </strong> {$web} </p>
                <p><strong>Budget:</strong> {$budget}</p>
    
      //this is where my checkbox results should be in the email body how do I code for them here?  
    
               <p><strong>Message: </strong> {$message} </p>
    
    
    
    
    
                <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
    
        mail("modsnap@gmail.com","Gimme a quote, Modsnap",$emailbody,$headers);
    
      }
    
      //what we need to return back to our form
      $returndata = array(
        'posted_form_data' => array(
          'name' => $name,
          'email' => $email,
          'telephone' => $telephone,
          'company'=> $company,
          'web'=> $web,
          'budget'=> $budget,
          'services'=> $services,
          'message' => $message
        ),
        'form_ok' => $formok,
        'errors' => $errors
      );
    
    
      //if this is not an ajax request
      if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
        //set session variables
        session_start();
        $_SESSION['cf_returndata'] = $returndata;
    
        //redirect back to form
        header('location: ' . $_SERVER['HTTP_REFERER']);
      }
    }