我想用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做后端处理。为什么你需要一个模板,如果它只是发送一封电子邮件然后重定向? –