ars_moriendi Posted June 4, 2009 Share Posted June 4, 2009 Hi there. I'm wondering if anyone knows of a server-side reason this simple mail form might not be posting the form data? It loads the appropriate receiving page, but $_POST holds nothing...huh? register_globals is on. Is there something I'm missing? THE FORM: <form name="contact-form" class="contact-form" action="contact.php" method="post" > <div style="margin:.5em auto 1em auto;"><span><?php echo $msg;?></span></div> <label for="name"><span>Name:</span> <input name="name" type="text" id="name" value="<?php echo @$_POST['name'];?>"/> </label> <label for="email"><span>Email:</span> <input name="email" type="text" id="email" value="<?php echo @$_POST['email'];?>"/></label> <label for="subject"><span>Subject:</span> <select name="subject" id="subject"> <option value=""><i>Select a Subject</i></option> <option value="coupon" <?php if (@$_POST['subject']=="coupon"){echo "SELECTED";}?>>I love coupons</option> <option value="food" <?php if (@$_POST['subject']=="food"){echo "SELECTED";}?>>I love your food</option> </select></label> <input type="hidden" value="1" name="form_submitted" /> <label for="message"><span>Message:</span> <textarea id="message" name="message" rows="4"><?php echo @$_POST['message'];?></textarea> </label> <p> </p> <input type="submit" value="Send" name=/> </form> THE FORM PROCESSING: if (@$_POST['form_submitted'] != "") { echo "Form Submitted"; if ($_POST['name'] != "") { $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if ($_POST['name'] == "") { $errors .= 'Please enter a valid name.<br/><br/>'; } } else { $errors .= 'Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>"; } } else { $errors .= 'Please enter your email address.<br/>'; } if ($_POST['subject'] !=""){ $_POST['subject'] = filter_var($_POST['subject'], FILTER_SANITIZE_STRING); if ($_POST['subject'] == "" ) { $errors .= 'Please select a subject for your message.<br/>'; } } else { $errors .= 'Please select a subject for your message.<br/>'; } if ($_POST['message'] != "") { $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING); if ($_POST['message'] == "") { $errors .= 'Please enter a message to send.<br/>'; } } else { $errors .= 'Please enter a message to send.<br/>'; } if (!$errors) { echo "No Errors"; $mail_to = '[email protected]'; $subject = 'New Mail'; $message = 'From: ' . $_POST['name'] . "\n"; $message .= 'Email: ' . $_POST['email'] . "\n"; $message .= 'Subject: ' . $_POST['subject'] . "\n"; $message .= "Message:\n" . $_POST['message'] . "\n\n"; mail($to, $subject, $message); $msg = "Thank you for your email!<br/><br/>"; } else { $msg = '<div style="color: red">' . $errors . '<br/></div>'; } } Any ideas? Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/ Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 your suppressing errors everywhere, take @ out and code properly so you don't get errors, not just ignore them. echo "Form Submitted"; do you really want to echo that before even checking the data, let alone trying to send the mail. $mail_to = '[email protected]'; $subject = 'New Mail'; $message = 'From: ' . $_POST['name'] . "\n"; $message .= 'Email: ' . $_POST['email'] . "\n"; $message .= 'Subject: ' . $_POST['subject'] . "\n"; $message .= "Message:\n" . $_POST['message'] . "\n\n"; mail($to, $subject, $message); $mail_to is not in the mail parameters mail($to, $subject, $message); should be mail($mail_to, $subject, $message); Also check the mail is sent <?php if(mail($mail_to, $subject, $message)) { echo "mail sent"; } else { echo "mail not sent"; } Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848948 Share on other sites More sharing options...
PFMaBiSmAd Posted June 4, 2009 Share Posted June 4, 2009 How do you know $_POST is empty, what are the symptoms? And are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that php would alert you to problems it finds? Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848950 Share on other sites More sharing options...
ars_moriendi Posted June 4, 2009 Author Share Posted June 4, 2009 your suppressing errors everywhere, take @ out and code properly so you don't get errors, not just ignore them. I suppress them because it's simpler to do so than to have a bunch of conditional statements checking that those vars exist. It's not important enough to make my scripts difficult to read. echo "Form Submitted"; do you really want to echo that before even checking the data, let alone trying to send the mail. Nope, just throwing in a flag to let me know when the darned thing decides to work. Of course I'll also finish validating that everything works once I figure out why my post data isn't showing up. Thanks for your notes. Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848975 Share on other sites More sharing options...
ars_moriendi Posted June 4, 2009 Author Share Posted June 4, 2009 How do you know $_POST is empty, what are the symptoms? And are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that php would alert you to problems it finds? print_r($_POST) displays nothing but Array(). Yes, I have error reporting turned on, 6143. And this is only happening on production, not on my local machine, so I know it's a server-side issue. Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848976 Share on other sites More sharing options...
PFMaBiSmAd Posted June 4, 2009 Share Posted June 4, 2009 Where exactly in the code was the print_r($_POST)? And are display_errors set to ON so that you would actually get errors output to the browser? Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848977 Share on other sites More sharing options...
ars_moriendi Posted June 4, 2009 Author Share Posted June 4, 2009 Where exactly in the code was the print_r($_POST)? And are display_errors set to ON so that you would actually get errors output to the browser? print_r($_POST) wasn't in the code I posted, but when I include it, I do so on the second line, right under <?php error_reporting(6143); in php.ini... display_errors is On error_reporting is 6135 Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848979 Share on other sites More sharing options...
PFMaBiSmAd Posted June 4, 2009 Share Posted June 4, 2009 And how do you know that the php.ini is actually causing the setting to be on in your script? We only see the information you provide in your posts. So far, there is no definitive information to for anyone to use to determine what is happening on your server. I suspect that host has something in place that is affecting all external variables or your form or your form processing code is doing something that is php configuration or php version specific. You need to fully post both and you need to make sure what the error_reporting and display_errors settings actually are. You also need to turn off register_globals because they could be overwriting your $_POST array if you have other variables by the same name in the remainder of the code (which is why you need to post all of the code that that makes up your form and your form processing page.) Edit: and that just reminded me that the $_POST array will be empty if you exceed the post_max_size setting. What does a phpinfo(); statement show for post_max_size? Post exactly what it shows in the output. Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-848989 Share on other sites More sharing options...
ars_moriendi Posted June 4, 2009 Author Share Posted June 4, 2009 And how do you know that the php.ini is actually causing the setting to be on in your script? We only see the information you provide in your posts. So far, there is no definitive information to for anyone to use to determine what is happening on your server. I suspect that host has something in place that is affecting all external variables or your form or your form processing code is doing something that is php configuration or php version specific. You need to fully post both and you need to make sure what the error_reporting and display_errors settings actually are. You also need to turn off register_globals because they could be overwriting your $_POST array if you have other variables by the same name in the remainder of the code (which is why you need to post all of the code that that makes up your form and your form processing page.) Edit: and that just reminded me that the $_POST array will be empty if you exceed the post_max_size setting. What does a phpinfo(); statement show for post_max_size? Post exactly what it shows in the output. I was going to post the output of phpinfo(), but I just had a thought. My initial statement about this site being production was inaccurate. The site I referred to is actually a test-bed. The domain name redirects to a subdirectory within another account. Accessing the site under the original domain rather than the redirected domain fixed the error. If I understood domain name redirection, I might be able to explain why exactly my perceived problem is not actually a problem, but who has time for that? You've all been very helpful. Now I'm going to close this thread and bid you all peaceful night. Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-849002 Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 I suppress them because it's simpler to do so than to have a bunch of conditional statements checking that those vars exist. It's not important enough to make my scripts difficult to read. echo isset($_POST['email']) ? $_POST['email'] : ''; Does that really make your script harder to read?? Link to comment https://forums.phpfreaks.com/topic/160858-solved-simple-form-wont-postwhat/#findComment-849076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.