使用wp_mail提交后重定向到另一个页面

时间:2019-02-13 作者:Henshall

在使用wp\\U mail提交表单后,我试图将用户重定向到另一个页面。

// Hooking up our functions to WordPress filters
add_filter( \'wp_mail_from\', \'wpb_sender_email\' );
add_filter( \'wp_mail_from_name\', \'wpb_sender_name\' );

// Email Sender
add_action(\'wp_ajax_mySendEmail\', \'mySendEmail\');
add_action(\'wp_ajax_nopriv_mySendEmail\', \'mySendEmail\');
function mySendEmail() {
    $name        = $_POST[\'name\'];
    $email       = $_POST[\'email\'];
    $contact_no  = $_POST[\'contact_no\'];
    $debts_value  = $_POST[\'debts_value\'];
    $how_much  = $_POST[\'how_much\'];
    $employment_type  = $_POST[\'employment_type\'];
    $page_id  = $_POST[\'page_id\'];
    $keyword  = $_POST[\'keyword\'];
    $to = [ "[email protected]" ];
    $subject = \'\';
    $mybody = \'\';
    $mybody .=\'<table>\';
    $mybody .=\'\';
    $mybody .=\'<p>The following information has been submitted via your website.</p>\';
    $mybody .=\'<tr><td><b>How</b></td><td>\'.$how_much.\'</td></tr>\';
    $mybody .=\'<tr><td><b>How</b></td><td>\'.$debts_value.\'</td></tr>\';
    $mybody .=\'<tr><td><b></b></td><td>\'.$employment_type.\'</td></tr>\';
    $mybody .=\'<tr><td><b>Name</b></td><td>\'.$name.\'</td></tr>\';
    $mybody .=\'<tr><td><b>Email</b></td><td>\'.$email.\'</td></tr>\';
    $mybody .=\'<tr><td><b>Contact No</b></td><td>\'.$contact_no.\'</td></tr>\';
    $mybody .=\'<tr><td><b>Page</b></td><td>\'.$page_id.\'</td></tr>\';
    $mybody .=\'<tr><td><b>Keyword</b></td><td>\'.$keyword.\'</td></tr>\';
    $mybody .=\'<p>Thank you,</p>\';
    $mybody .=\'<p></p>\';
    $mybody .=\'</table>\';
    $body = $mybody;
    $headers = array(\'Content-Type: text/html; charset=UTF-8\');
    $sendStatus = wp_mail( $to, $subject, $body, $headers );

    if ( $sendStatus ){
        wp_redirect( \'/thank-you/\', 301);
        exit;
    }

    // print_r($sendStatus); die;
}
它似乎只是在重定向,不知道我做错了什么?

1 个回复
SO网友:Jignesh Patel

我想找不到主页url。并确保此条件为真。if ( $sendStatus ){ }

请像这样试试。

<?php wp_redirect( home_url(\'/thank-you/\', 301) ); exit; ?>