-3

I'm having a very difficult time getting my PHP and HTML to work together on an email form. This is a website I've adopted and I'm not sure what I'm missing. I'm basically building a form within a modal so users have to register their email before downloading assets. So, once the form is sent they'll be able to connect to the next page to download what they needed. The trouble I'm having is with the form. Whatever I try isn't working. Help!

 <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Download 3D Models</h4>
      </div>
      <div class="modal-body">
       <div class="container slate">
      <div class="row">
        <div class="col-md-6">
        <form name="send_form_email" action="../quform/send_form_email.php" method="get" enctype="multipart/form-data">
        <div class="quform-elements">
         <div class="form-group">
                <label for="email">Name <span class="text-danger">*</span></label> 
                <input id="name" type="text" name="name" class="form-control" placeholder="Name">
              </div>
              <div class="form-group">
                <label for="company">Company / Firm <span class="text-danger">*</span></label>
                <input id="company" type="text" name="email" class="form-control" placeholder="Company / Firm">
              </div>
              <div class="form-group">
                <label for="email">Email<span class="text-danger">*</span></label>
                <input id="email" type="text" name="email" class="form-control" placeholder="Email">
              </div>
             <div class="quform-element quform-element-recaptcha">
                <div class="quform-spacer">
                  <label>Are you human?<span class="text-danger">*</span></label>
                  <div class="quform-input" style="width: 250px;">
                    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
                    <div class="g-recaptcha" data-sitekey="6Le2WvkSAAAAAP9bLeD4OaiVYvDrHXhcKaFo1chy"></div>
                    <noscript>
                      <div style="width: 302px; height: 352px;">
                        <div style="width: 302px; height: 352px; position: relative;">
                          <div style="width: 302px; height: 352px; position: absolute;">
                            <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Le2WvkSAAAAAP9bLeD4OaiVYvDrHXhcKaFo1chy" frameborder="0" scrolling="no" style="width: 302px; height:352px; border-style: none;">
                            </iframe>
                          </div>
                          <div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 5px;">
                            <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;"></textarea>
                         </div>
                        </div>
                      </div>
                    </noscript>
                  </div>
                </div>
              </div><!--/.recaptcha -->
              <div class="form-group">
                <button type="reset" class="btn btn-default">Cancel</button>
                <button type="submit" class="btn btn-primary" value="Send">Send</button>
              </div>
            </div> <!--/. quform-elements-->
          </form>      
        </div> <!--/.col-md-6-->

<?php
$name = $_POST['name']; //'name' has to be the same as the name value on the form input element
$company = $_POST['company'];
$email = $_POST['email'];
$human = $_POST['human'];
$from = $_POST['email'];
$to = 'xxx@gmail.com'; //set to the default email address
$subject = $_POST['3D Model Request'];
$body = "From: $name\n Company: $company/n E-Mail: $email\n";

$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();

if(isset($_POST['submit']) && ($_POST['human']) == '4') {               
mail ($to, $subject, $body, $headers);  //mail sends it to the SMTP server side which sends the email
    echo "<p>Your message has been sent!</p>";
} 

else { 
    echo "<p>Something went wrong, go back and try again!</p>"; 
} 
if (!isset($_POST['submit']) && ($_POST['human']) != '4') {
echo "<p>You answered the anti-spam question incorrectly!</p>";
}
?>
  • Could it be that the email is sent to `$to = 'xxx@gmail.com';`? – Jite Jun 16 '17 at 20:42
  • 2
    You sending get data in your form, while waiting for POST in php, you should change `method="get"` to `method="post"` – Artem Layko Jun 16 '17 at 20:42
  • I just put that in as a placeholder to protect my email. Using my real email hasn't helped. – JillPut Jun 16 '17 at 20:42
  • "Whatever I try isn't working." What is the behavior you're expecting, and what is the behavior you're getting? – Goose Jun 16 '17 at 20:52
  • I'm expecting the email to be sent to myself. I'm currently getting a blank page with the code after I click 'submit'. I'm using my MAMP test server, if that helps... – JillPut Jun 16 '17 at 20:56
  • @JillPut If you are receiving php code on your page, so seem's like your web-server isn't configured or not running. – Artem Layko Jun 16 '17 at 20:59

2 Answers2

0

Your form sending data in get, but on php side you are waiting to get data from POST, change method of your form to make it work. Should be method="POST" Also you have multiple email inputs(they have same name). And you not receiving $human = $_POST['human']; and $subject = $_POST['3D Model Request']; from this form

Artem Layko
  • 78
  • 11
0

Your form has method="get" and your php logic is expecting POST data which is never set because you're submitting via get.

Change the form to have method="POST" instead.

<form name="send_form_email" action="../quform/send_form_email.php" method="POST" enctype="multipart/form-data">

Ryan Tuosto
  • 1,941
  • 15
  • 23
  • I've tried that as well and it's still not working. Any other ideas? – JillPut Jun 16 '17 at 20:47
  • do var_dump($_POST) at the top of your PHP file and see if the data is even being submitted to your page for processing. – Ryan Tuosto Jun 16 '17 at 20:48
  • Added. After I hit 'submit' on my form, it gives me a blank page with the code. So something is just not processing right. – JillPut Jun 16 '17 at 20:50
  • @JillPut If it gives you blank page with your php code you should check your web-server settings to enable php – Artem Layko Jun 16 '17 at 20:52