Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Matthew Schad
Matthew Schad
9,381 Points

PHP Form is submitting "0"

Does anybody know why this form is returning the value of "0" to my email?

<?php

if (isset($_POST['email'])) {

      //Email information
      $admin_email = "mschad@brighterhomesphotography.com";
      $first = $_POST['first_name'];
      $last = $_POST['last_name'];
      $phone = $_POST['phone'];
      $email = $_POST['email'];
      $address = $_POST['address'];
      $city = $_POST['city'];
      $zip = $_POST['zip'];
      $sqft = $_POST['SQFT'];
      $radio_option = $_POST['res_comm'];
      $projDescription = $_POST['comment'];

      $message = "Full Name: " . $first . " " . $last . "\n";
      $message += "Phone Number: " . $phone . "\n";
      $message += "Email Address: " . $email . "\n";
      $message += "Address: " . $address . "\n";
      $message += "City: " . $city . "\n";
      $message += "Zip Code: " . $zip . "\n";
      $message += "Square Feet: " . $sqft . "\n";
      $message += "Residential or Commercial: " . $radio_option . "\n";
      $message += "Project Description: " . $projDescription . "\n";
      $message += "\n" . "used the form on the site and is requesting a callback.";

      //send email - This is the mail function format.
          // mail ($to, $subject, $message, $additional-headers)
      mail($admin_email, 'Form Submitted', $message );

      //Email response
      echo "Our photographer will be in touch with you within 24 hours.";
      }
?>

Here is the HTML..

    <div class="form-group">
          <label class="col-md-4 control-label">First Name</label>
          <div class="col-md-4 inputGroupContainer">
          <div class="input-group">
          <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
          <input  name="first_name" placeholder="First Name" class="form-control"  type="text">
            </div>
          </div>
        </div>

        <!-- Text input-->

        <div class="form-group">
          <label class="col-md-4 control-label" >Last Name</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
          <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
          <input name="last_name" placeholder="Last Name" class="form-control"  type="text">
            </div>
          </div>
        </div>

        <!-- Text input-->
               <div class="form-group">
          <label class="col-md-4 control-label">E-Mail</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
          <input name="email" placeholder="E-Mail Address" class="form-control"  type="text">
            </div>
          </div>
        </div>


        <!-- Text input-->

        <div class="form-group">
          <label class="col-md-4 control-label">Phone #</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
          <input name="phone" placeholder="(845)555-1212" class="form-control" type="text">
            </div>
          </div>
        </div>

        <!-- Text input-->

        <div class="form-group">
          <label class="col-md-4 control-label">Address</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
          <input name="address" placeholder="Address" class="form-control" type="text">
            </div>
          </div>
        </div>



        <!-- Text input-->

        <div class="form-group">
          <label class="col-md-4 control-label">City</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
                <input name="city" placeholder="City" class="form-control"  type="text">
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-4 control-label">Zip Code</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
          <input name="zip" placeholder="Zip Code" class="form-control"  type="text">
            </div>
        </div>
        </div>

        <!-- Select Basic -->

        <div class="form-group">
          <label class="col-md-4 control-label">Property Size</label>
            <div class="col-md-4 selectContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
            <select name="SQFT" class="form-control selectpicker" >
              <option value="" >Please select your Square Footage</option>
              <option value="1-3250">0 – 3250 SQ FT</option>
              <option value="3250-5000">3250 – 5000 SQ FT</option>
              <option value="5000-7000">5000 – 7000 SQ FT</option>
              <option value="7000+">7000+ SQ FT</option>
            </select>
          </div>
        </div>
        </div>

        <!-- Text input-->


        <!-- radio checks -->
         <div class="form-group">
                                <label class="col-md-4 control-label">Residential or Commercial?</label>
                                <div class="col-md-4">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="res_comm" value="Residential" /> Residential
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="res_comm" value="Commercial" /> Commercial
                                        </label>
                                    </div>
                                </div>
                            </div>

        <!-- Text area -->

        <div class="form-group">
          <label class="col-md-4 control-label">Project Description</label>
            <div class="col-md-4 inputGroupContainer">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
                    <textarea class="form-control" name="comment" placeholder="Project Description"></textarea>
          </div>
          </div>
        </div>

1 Answer

Matthew Schad
Matthew Schad
9,381 Points

Nevermind! Should have been concatenating vars into the message with .=, not +=.