我的邮件发送后如何重定向(wp_mail)?

时间:2017-07-19 13:44:33

标签: javascript php wordpress

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

<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@hotmail.com", "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

}

我非常希望在发送电子邮件后转到感谢页面。

1 个答案:

答案 0 :(得分: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@hotmail.com", "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";';
            }