我想用wp_mail發送一封電子郵件,然後,如果郵件發送成功,將用戶重定向到另一個頁面(或者,如果不成功,則返回錯誤頁面)。無法讓wp_redirect工作
我的代碼如下所示。該電子郵件實際上是發送,所以wp_mail工作,但我不能讓重定向工作。
<?php
/* Template Name: Redirect Template */
?>
<?php
$to = "[email protected]";
$subject = 'This is a test.';
$message = 'This is a test of the wp_mail function.';
$headers = '';
$sent_message = wp_mail($to, $subject, $message, $headers);
if ($sent_message) {
$url_1 = "http://www.some-url.com";
wp_redirect($url_1);
exit();
} else {
$url_2 = "http://www.some-other_url.com";
wp_redirect($url_2);
exit();
}
?>
<?php get_header(); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('content', 'page'); ?>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>
你的意思是什麼重定向「不工作」?怎麼了? – rnevius
我沒有重定向到指定的頁面。在我上面的代碼中,我沒有發送到新的URL,例如'http://www.some-url.com' – Mekong
頁面模板是做這種處理的錯誤地方。已經指出,直接的問題是你的文件中有空白,但根本問題是你使用你的UI做後端處理。爲什麼你需要一個模板,如果它只是發送一封電子郵件然後重定向? –