Reputation: 4078
I am using phpmailer to send emails, when email is successfully sent then i want to redirect the page to other page, but it is not working.
I tried using server side redirect ie header();
but it is not working.
when i try it for client side its perfectly redirect to other page.
And i have not used any sessions
on this page or the other page.
below is the code what i have tried
if(!$mail->Send()){
echo "Mailer Error: ". $mail->ErrorInfo;
}else{
//echo "Message sent!";
header('Location: contactus-thankyou.php');
?>
<!-- <meta http-equiv="refresh" content="0; url=contactus-thankyou.php" /> -->
<?php
}
Upvotes: 0
Views: 5114
Reputation: 5
The reason is that the output is getting buffered before the header loaction statement and header statement usually don't like echo or outputs from server before it.
just use obs_start();
at the top and obs_end_flush();
at the end :
example:
obs_start();
php mailer script starts.........
...
obs_end_flush();
header("Location: index.php");
Upvotes: 0
Reputation: 1
You can use jQuery to redirect instead and it works.
<script>
$(document).ready(function(){
setTimeout(function(){
location.href="../index.php";
});
});
</script>
Upvotes: 0
Reputation: 3390
try removing the space between location and the url
header('Location:contactus-thankyou.php');
Upvotes: 0
Reputation: 1894
you can use
echo "<script language='javascript' type='text/javascript'>location.href='contactus-thankyou.php'</script>";
in place of
header('Location: contactus-thankyou.php');
Upvotes: -1