2015-10-08 64 views
0

我无法获取此代码不显示感谢您不完整提交的模块。我也希望页面重定向到始发页面(用弹出模块确认或模块页面上的错误将是最佳的),或者只是重定向到始发页面,而不必为每个页面创建一个新的PHP文件联系表单已打开。我有一些。Bootstrap联系表单模块问题

现在它可以发送邮件,但只需键入一个空白页面,并使用浏览器后退按钮返回原始页面。即使输入正确,它也会激发(谢谢)模块。是否有可能得到这方面的帮助?

<form class="o-form" id="contactForm" action="php/contact.php" method="post"> 
          <input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="email"> 
          <textarea name="message" id="message" required="required placeholder="message"></textarea> 
          <input type="submit" value="send" class="send-button"> 
         </form> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="copyright"> 
     <span> 
      anthonygallina 
     </span> 
     </div> 
    </footer> 
    <div class="th-popup"> 
     <div class="massage-th"> 
      <h1>Thank You!</h1> 
      <p>We apreciate your visit to our home page. We will contact you soon!</p> 
     </div> 
    </div> 

<script src="js/jquery-1.11.1.min.js"></script> 
<script src="js/all.js"></script> 
<script src="js/jquery.mixitup.min.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script src="js/idangerous.swiper.min.js"></script> 
</body> 
</html> 

<?php 

,另一部分

// Define some constants 
define("RECIPIENT_NAME", "YOURNAME"); 
define("RECIPIENT_EMAIL", "[email protected]"); 
define("EMAIL_SUBJECT", "Visitor Message"); 

// Read the form values 
$success = false; 
$senderEmail = isset($_POST['senderEmail']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail']) : ""; 
$message = isset($_POST['message']) ? preg_replace("/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message']) : ""; 

// If all values exist, send the email 
if ($senderEmail && $message) { 
    $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">"; 
    $headers = "From: " . $senderEmail . " <" . $senderEmail . ">"; 
    $success = mail($recipient, EMAIL_SUBJECT, $message, $headers); 
} 

// Return an appropriate response to the browser 
if (isset($_GET["ajax"])) { 
    echo $success ? "success" : "error"; 
} else { 
?> 
<html> 
    <head> 
    <title>Thanks!</title> 
    </head> 
    <body> 
    <?php if ($success) echo "<p>Thanks for sending your message! We'll get back to you soon.</p>" ?> 
    <?php if (!$success) echo "<p>There was a problem sending your message. Please try again.</p>" ?> 
    <p>Click your browser's Back button to return to the page.</p> 
    </body> 
</html> 
<?php 
} 
?> 
+0

读第二段 –

+0

我不知道什么是不工作时,当我调试它,当我读它时,它是好的。这就是我在这里发布的原因。 –

+0

'if(isset($ _ GET [“ajax”])){ echo $ success? “成功”:“错误”; '不清楚。 –

回答

1

你只需要$success玩这样的:

<?php 
// Define some constants 
define("RECIPIENT_NAME", "YOURNAME"); 
define("RECIPIENT_EMAIL", "[email protected]"); 
define("EMAIL_SUBJECT", "Visitor Message"); 

// Read the form values 
$success = false; 
$senderEmail = isset($_POST['senderEmail']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail']) : ""; 
$message = isset($_POST['message']) ? preg_replace("/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message']) : ""; 

// If all values exist, send the email 
if ($senderEmail && $message) { 
    $formSubmitted = true; 
    $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">"; 
    $headers = "From: " . $senderEmail . " <" . $senderEmail . ">"; 
    $success = mail($recipient, EMAIL_SUBJECT, $message, $headers); 
} 

// Return an appropriate response to the browser 
if (isset($_GET["ajax"])) { 
    echo $success ? "success" : "error"; 
} ?> 
<!--Your contact.php page--> 

<form class="o-form" id="contactForm" action="php/contact.php" method="post"> 
    <input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="email"> 
    <textarea name="message" id="message" required="required placeholder=" message"></textarea> 
    <input type="submit" value="send" class="send-button"> 
</form> 
</div> 
</div> 
</div> 
</div> 
<div class="copyright"> 
     <span> 
      anthonygallina 
     </span> 
</div> 
</footer> 
<div class="th-popup"> 
    <div class="massage-th"> 
     <h1>Thank You!</h1> 

     <p>We apreciate your visit to our home page. We will contact you soon!</p> 
    </div> 
</div> 

<script src="js/jquery-1.11.1.min.js"></script> 
<script src="js/all.js"></script> 
<script src="js/jquery.mixitup.min.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script src="js/idangerous.swiper.min.js"></script> 
<script> 

    <?php 
    if($formSubmitted) 
    { 
     if ($success) 
     { 
      $msg="<p>Thanks for sending your message! We'll get back to you soon.</p>"; 
     } 
     else 
     { 
      $msg="<p>There was a problem sending your message. Please try again.</p>"; 
     } 
    //Open your confirmation or error model here using $msg 
    } 
    ?> 
</script> 
</body> 
</html> 
+0

这与我应用此更改的情况是一样的。 –

+0

'回声在这里“;退出;''是我通常用来添加断点。你为什么不尝试一样,看看它在哪里打破。在这个例子中,我点击相同的URL提交表单并设置一些PHP变量,如果该变量设置和邮件设置成功,然后根据'$ success'的值,我显示模式.. – Rayon