ob_start(); //your code echo "Data has been submitted to $to!"; mail($to, $subject, $body); header("Location: http://www.google.com"); ob_end_flush();