2017-07-19 56 views
0

我想知道如何重定向后,我的邮件已发送我试着用javascript做,我也试过它与header("Location: "www.google.com""),但它不会工作,我不知道如何解决这个问题。我真的希望有人能帮助我。这是我的代码:我的邮件发送后(wp_mail)如何重定向?

<script> 
     var text; 
     function show(param_div_id,button) {  
      <?php 
      if(isset($_POST['reset'])) { 
       $headers = "MIME-Version: 1.0" . "\n"; 
       $headers .= "MIME-Version: 1.0\r\n"; 
       $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
       $result = str_ireplace("undefined" , "" , $_POST["ll"][0]); 
       $email = $_POST["ll"][1]; 
       wp_mail("[email protected]", "email","Dear, <br><br>". 
        "From test filled in by " .$email. " this came out: <br><br>". 
        $result. "<br><br> Greetings, <br> website.nl" 
        ,$headers); 
      } 
      ?>document.getElementById('main_place').innerHTML = document.getElementById(param_div_id).innerHTML; 
      text = text + " " + button; 
      var ll=document.getElementById('ll'); 
      ll.value=text; 
      console.log(button) 
     } 
    </script> 
    <?php 

} 

我真的很喜欢它去感谢您网页发送电子邮件后。

+0

你在哪里尝试并把JavaScript重定向? – CumminUp07

+0

在wp_mail之后和if(isset($ _ POST ['reset'])) –

+0

之后,您可以使用wp_redirect('“/ thank-you-page”,int $ status = 302)https://developer.wordpress .org/reference/functions/wp_redirect/ – VA79

回答

0

一旦输出开始,包括空格在内,PHP不能修改头文件。您可以使用JavaScript重定向页面。你可以让你的if语句回声javascript window.location.href='www.stackoverflow.com'

if(isset($_POST['reset'])) { 
       $headers = "MIME-Version: 1.0" . "\n"; 
       $headers .= "MIME-Version: 1.0\r\n"; 
       $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
       $result = str_ireplace("undefined" , "" , $_POST["ll"][0]); 
       $email = $_POST["ll"][1]; 
       wp_mail("[email protected]", "email","Dear, <br><br>". 
        "From test filled in by " .$email. " this came out: <br><br>". 
        $result. "<br><br> Greetings, <br> website.nl" 
        ,$headers); 
       echo 'window.location.href="www.stackoverflow.com";'; 
      } 
+0

嘿,谢谢,但我试过这个,它只是不重定向,它似乎像它会在邮件后面结束代码,然后我不能再放任何东西。 –

+0

我在代码中有一个错误,php会失败,我在echo语句里面添加了双引号,并且在最后需要分号,试试 – CumminUp07

+0

它仍然没有重定向。 –