kayz100 Posted March 5, 2014 Share Posted March 5, 2014 Hi guys How do I get a thank you message on the same page instead of redirecting the message to a different page as on the script here - header('Location: thanks.html'); Also I want the errors to be echoed in front of the field concerned as in name, email, subject, message <?php $myemail = "hila@gmail.com"; $name = check_input($_POST['name'], "Enter your name"); //error or success message echoed here $subject = check_input($_POST['subject'], "Enter a subject");//error or success message echoed here $email = check_input($_POST['email']);//error or success message echoed here $message = check_input($_POST['message'], "Write your message");//error or success message echoed here if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } $message = " Name: $name E-mail: $email Subject: $subject Message: $message "; mail($myemail, $subject, $message); //This is where the problem is header('Location: thanks.html'); //Want to have this message on the same page exit(); function check_input($data, $problem=''){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0){ show_error($problem); } return $data; } function show_error($myError) { ?> <html><head> <title> email 2014</title> </head> <body> <strong><?php echo $myError; ?></strong><br /><br /> <form class="email" action="" method="post"> <p>Name:</p> <input type="text" name="name" /> <p>E-mail:</p> <input type="text" name="email" /> <p>Subject:</p> <input type="text" name="subject" /> <p>Message:</p> <textarea name="message"></textarea></p> <input class="send" type="submit" value="Send"> </form> <?php exit(); } ?> </body></html> Quote Link to comment Share on other sites More sharing options...
jairathnem Posted March 5, 2014 Share Posted March 5, 2014 you could echo the message directly. echo "Thank you."; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.