I am having problems getting php to redirect after processing an email message. I've tried all of the solutions mentioned on this page, as well as some involving javascript with no luck. Here are the relevant portions of my code:
function redirect($url) {
ob_start();
header('Location: '.$url);
ob_end_flush();
exit();
}
if ( isset($_REQUEST['sendemail']) ) {
header("Content-Type: text/plain");
header("X-Node: $hostname");
$from = $_REQUEST['from'];
$name = $_REQUEST['name'];
$toemail = "djsuson@gmail.com";
$subject = "Customer question";
$message = $_REQUEST['message'];
ob_start(); //start capturing output buffer because we want to change output to html
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->IsSMTP();
if ( strpos($hostname, 'cpnl') === FALSE ) //if not cPanel
$mail->Host = 'relay-hosting.secureserver.net';
else
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->From = $from;
$mail->FromName = $name;
$mail->AddAddress($toemail);
$mail->Subject = $subject;
$mail->Body = $message;
$mailresult = $mail->Send();
$mailconversation = nl2br(htmlspecialchars(ob_get_clean()));
if ( !$mailresult ) {
echo 'FAIL: ' . $mail->ErrorInfo . '<br />' . $mailconversation;
redirect('http://otterlywoods.com/failure.html');
} else {
echo $mailconversation;
redirect('http://otterlywoods.com/success.html');
}
Any help on this would be appreciated.