loydster Posted June 20, 2008 Share Posted June 20, 2008 I am getting post backs from this form. Can anyone give me a clue what I'm doing wrong? Also any tip on how to make this spam proof? Thanks. <?php ini_set("sendmail_from", "loyd@loydster.com"); if(isset($_POST['submit'])) { $to = "loydster@comline.com"; $subject = "Inquiry or Comment"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $option = $_POST['radio']; $dropdown = $_POST['drop_down']; foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n"; echo "Thank you for contacting $to!"; mail($to, $subject, $body); } else { echo "Error on email posting."; } ?> if(isset($_POST['submit'])) { ON SUBMIT I GET THIS ERROR MESSAGE: Notice: Undefined variable: check_msg in d:\Customers\user1220675\www\mailer.php on line 13 Thank you for contacting loydster@comline.com!if(isset($_POST['submit'])) {19 Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 how bout you try to initialize $check_msg to whatever value you want before going inside foreach(). i think its because you are using .= right away without initializing (a guess, ahehe). anti spam? try captcha or use the string: plus or minus in your website. Quote Link to comment Share on other sites More sharing options...
whizard Posted June 20, 2008 Share Posted June 20, 2008 That's not an error, its a notice, which is a non-fatal message which just gives you information about an irregularity in your script. In this case, the first time the script goes through the foreach loop, it is asked to append "Checked: $value\n"; to the variable $check_msg, which doesn't exist, hence the undefined error. To fix it, just add $check_msg = ""; before the foreach loop. Also, you are getting the text about if(isset..... because you have it written outside the closing PHP tag. Dan ahh... beaten by bluejay. Quote Link to comment Share on other sites More sharing options...
loydster Posted June 20, 2008 Author Share Posted June 20, 2008 Thank you Dan and Bluejay. Is there anything I can add to the code to refresh the HTML after the PHP mail is submitted? I get the "Thank you for contacting me" screen, but if I hit the back button to go back to my site, the form is still populated. I'm assuming that i need to beef up the HTML to refresh the page when the "Submit" button is clicked? Thanks again for the help. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 you can use meta tag on that to automatically refreah the page after several minutes to a page you specify: <meta http-equiv="refresh" content="delay_in_seconds; url=specify_url_here" /> cheers, Jay Quote Link to comment Share on other sites More sharing options...
loydster Posted June 20, 2008 Author Share Posted June 20, 2008 Use the metatag in my HTML you mean? Thanks again. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 yep... together with whatever text you want to show to the client. Quote Link to comment Share on other sites More sharing options...
loydster Posted June 20, 2008 Author Share Posted June 20, 2008 Excuse my density, but is this the scenario? I add the metatag to my HTML on the "Contact" page. The user enters his info and submits the PHP contact form. The reply page "Thank you..." loads. If the user goes back the page is still populated with the data he/she entered, right? If I set the page to refresh itself automatically, don't I stand a good chance of losing posts from end users? Is there any way to set the PHP "thank you" response page to redirect to the "contact" page? This would refresh the page automatically as well and not generate uneeded or unwanted refresh of the page. Thank you for your patience. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 Is there any way to set the PHP "thank you" response page to redirect to the "contact" page? This would refresh the page automatically as well and not generate uneeded or unwanted refresh of the page. Put the meta tag at the thank you page then that meta tag to redirect to contact page after several seconds and you may also include a link to contact if the user want to redirect right away and dont want to wait. back is always present... if you want to remove that... then check its browsing history and forbid the client. a little Google will do. Quote Link to comment Share on other sites More sharing options...
loydster Posted June 20, 2008 Author Share Posted June 20, 2008 I am unable to find good references to this. My code thus far: <?php ini_set("sendmail_from", "loyd@loydster.com"); $to = "loydster@comline.com"; $subject = "Inquiry or Comment"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $option = $_POST['radio']; $dropdown = $_POST['drop_down']; $check_msg = ""; foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } if(isset($_POST['submit'])) { $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n"; echo "Thank you for contacting loydster.com"; mail($to, $subject, $body); } else { echo "Message Error."; When I try adding the <meta http-equiv="refresh" content="delay_in_seconds; url=specify_url_here" /> tag to the PHP to initiate my thankyou.html page, the PHP of course displays only text "thankyou.htm". I know I am close here but what am I doing wrong? I want the PHP to display the thankyou.html upon successful posting of the message. This would automatically refresh the page as the user would have to click a menu page from there. Thank you. } ?> Quote Link to comment Share on other sites More sharing options...
whizard Posted June 21, 2008 Share Posted June 21, 2008 use the header command in your PHP before any output is sent to the browser (IE print or echo statemnt, etc): header("Location: thankYou.html"); HTH Dan Quote Link to comment Share on other sites More sharing options...
loydster Posted June 21, 2008 Author Share Posted June 21, 2008 Thank you again. I fixed er up and it works like a champ. 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.