2017-07-19 8 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

まだリダイレクトされていません。 –