wordpress - Cannot get wp_redirect to work -
i'm trying send email using wp_mail , then, if mail sent successfully, redirect user page (or, if not successful, error page).
my code shown below. email sent, wp_mail working, cannot redirect work.
<?php /* template name: redirect template */ ?> <?php $to = "info@some-domain.com"; $subject = 'this test.'; $message = 'this test of 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 loop. ?> <?php get_footer(); ?>
you need rid of white space between closing , opening php tags. because have space, wordpress initiating output before redirect runs (which isn't allowed). rid of following @ top of file:
?> <?php
so top of file becomes:
<?php /* template name: redirect template */ $to = "info@some-domain.com";
Comments
Post a Comment