2017-06-16 77 views
-3

我很難讓我的PHP和HTML在電子郵件表單上一起工作。這是我採用的網站,我不確定我錯過了什麼。我基本上是在一種模式下構建一個表單,因此用戶必須在下載資產之前註冊他們的電子郵件。所以,一旦表單被髮送,他們將能夠連接到下一頁來下載他們需要的東西。我遇到的麻煩是與形式。無論我嘗試什麼都行不通。幫幫我!未使用html連接的PHP代碼

<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 = '[email protected]'; //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>"; 
 
} 
 
?>

+0

難道電子郵件發送到'$到= '[email protected]';'? – Jite

+2

你發送的數據在你的表單中,而在等待POST在php中,你應該改變'method =「get」'爲'method =「post」' –

+0

我只是把它作爲佔位符來保護我的電子郵件。使用我的真實電子郵件沒有幫助。 – JillPut

回答

0

你的形式發送的獲取數據,但在PHP端你正在等待從POST獲取數據,更改method您的形式,使之工作。 應該是method="POST" 也有多個email輸入(它們具有相同的名稱)。 你不能從這種形式

0

在窗體中有method="get"接收$human = $_POST['human'];$subject = $_POST['3D Model Request'];和你的PHP邏輯期待,因爲你通過GET提交這是從來沒有設置POST數據。

更改表格以代替method="POST"

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

+0

我試過了,它仍然不能正常工作。任何其他想法? – JillPut

+0

在你的PHP文件的頂部做var_dump($ _ POST),看看數據是否被提交到你的頁面進行處理。 –

+0

已添加。在我的表單上點擊「提交」後,它給了我一個帶有代碼的空白頁面。所以有些東西只是不能正確處理。 – JillPut