joe90 Posted May 19, 2010 Share Posted May 19, 2010 First post on PHP Freaks - hope you can help. When visitors want to leave a comment on my site I've built a php script to have the contact form input into MySQL, however i now need to show the visitor a receipt page simply saying thanks and also email the website owner the visitors details. Any help much appreciated. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted May 19, 2010 Share Posted May 19, 2010 Check to see if the data has been inserted into the database and echo a thank you message, then send an e-mail using the mail() function. E.g. <?php // MYSQL CONNECTION CODE $email = trim($_POST['email']); // This is the users e-mail address $subject = trim($_POST['subject']); $message = trim($_POST['message']); if (isset($_POST['submit'])) { $sql = mysql_query(sprintf("INSERT INTO contact ( email, subject, message ) VALUES ( '%s', '%s', '%s' )", mysql_real_escape_string($email), mysql_real_escape_string($subject), mysql_real_escape_string($message)) ); if ($sql) { echo 'Thank you for contacting us.'; // Header information $from = 'From: '. $email ."\r\n" . 'Reply-To: '. $email; mail('admin@domain.com', $subject, $message, $headers); } else { echo 'Sorry your request could not be completed.'; } } ?> That's very basic and it should be improved upon and secured properly with form validation. Quote Link to comment Share on other sites More sharing options...
joe90 Posted May 19, 2010 Author Share Posted May 19, 2010 I'll give that coding a try but it's not just a 'Thank You' message I'm also looking for but for the site to display a php page with all the website navigation on, headers etc - or am i approaching this the wrong way? 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.