if(mail($to,$subject,$msg,$headers)){ header("Location: http://www.mysite.com/contact/thankyou.php"); echo "message sent"; exit; }else{ $message = "Sorry, there was a problem with sending the mail."; echo "Error"; }