Sebolains Posted May 10, 2010 Share Posted May 10, 2010 Hey guys! I've been coding this contact form in php. For some reason, it doesn't seem to work (ie. it always returns "There was a problem sending your feedback, please try again later.") Now, the funny thing, is that I'm quite sure it used to work perfectly, but now it just... doesn't. I don't remember changing anything, and I doubt I did. I'm really going insane here. I'd appreciate any help you can provide me with Here's the code: <?php $myemail = '[email protected]'; $subject = 'DCanime General Contact'; $op = $_POST[op]; if($op == 'contact') { $name = stripslashes($_POST[name]); $email = stripslashes($_POST[email]); $category = stripslashes($_POST[category]); $text = stripslashes($_POST[text]); $referer = $_POST[referer]; $remote_host = $_SERVER[REMOTE_ADDR]; $server = $_SERVER[sERVER_NAME]; $browser = $_SERVER[HTTP_USER_AGENT]; if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email)) { $status = "We're sorry, but you've entered an incorrect email address."; } if(!$name) { $status .= "Please enter your name."; } if(!$text) { $status .= "Please enter a message."; } if(!$status) { $header = "From: $emailrnReply-To: $emailrn"; $message = " Name: $name Referer: $referer Site: $server Remote Host: $remote_host Remote Browser: $browser Category: $category $text "; if(mail($myemail, $subject, $message, $header)) { $status = "Thank you for your Feedback!!"; } else { $status = "There was a problem sending your feedback, please try again later."; } } else { $status .= "Please press <u>back</u> on your browser to resubmit."; } } $referer = $_SERVER[HTTP_REFERER]; if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer)) { unset($referer); } ?> <h1>Contact Us</h1> <form method="post" action="<?php print $_SELF; ?>"> <p class="result"><?php print $status; ?></p> <input type="hidden" name="op" value="contact"> <input type="hidden" name="referer" value="<?php print $referer; ?>"> <p> <label>Name:</label> <input class="text" type="text" name="name"> </p> <p> <label>Email address:</label> <input class="text" type="text" name="email"> </p> <p> <label>Category:</label> <select name="category"> <option value="general">General Inquires</option> <option value="problem">Report a Problem</option> <option value="team">Team Application</option> <option value="other">Other</option> </select> </p> <p> <label>Message:</label> <textarea name="text"></textarea> </p> <input type="submit" class="submit" value="Send!" /> </form> The website is connected to a .css, so the classes come from there - no big deal. Anyways, THANK YOU SO MUCH FOR YOUR TIME! I appreciate any kind of feedback! THANKS AGAIN, Seb. Link to comment https://forums.phpfreaks.com/topic/201296-contact-form-help/ Share on other sites More sharing options...
zimmo Posted May 10, 2010 Share Posted May 10, 2010 Hi I have just tested your code and got it working and added a couple of features for you, they need finishing off but made a start for you, so that if it returns the error you dont lose what you just typed. <?php $myemail = 'email address here'; $subject = 'DCanime General Contact'; $op = $_POST[op]; if($op == 'contact') { $name = stripslashes($_POST[name]); $email = stripslashes($_POST[email]); $category = stripslashes($_POST[category]); $text = stripslashes($_POST[text]); $referer = $_POST[referer]; $remote_host = $_SERVER[REMOTE_ADDR]; $server = $_SERVER[sERVER_NAME]; $browser = $_SERVER[HTTP_USER_AGENT]; if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email)) { $status = "We're sorry, but you've entered an incorrect email address."; } if(!$name) { $status .= "Please enter your name."; } if(!$text) { $status .= "Please enter a message."; } if(!$status) { $header = "From: $emailrnReply-To: $emailrn"; $message = " Name: $name Referer: $referer Site: $server Remote Host: $remote_host Remote Browser: $browser Category: $category $text "; if(mail($myemail, $subject, $header, $message)) { $status = "Thank you for your Feedback!!"; } else { $status = "There was a problem sending your feedback, please try again later."; } } else { $status .= "Please press <u>back</u> on your browser to resubmit."; } } $referer = $_SERVER[HTTP_REFERER]; if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer)) { unset($referer); } ?> <html> <body> <h1>Contact Us</h1> <form method="post" action="<?php print $_SELF; ?>"> <p class="result"><?php print $status; ?></p> <input type="hidden" name="op" value="contact"> <input type="hidden" name="referer" value="<?php print $referer; ?>"> <p> <label>Name:</label> <input class="text" type="text" name="name" value="<?php print $name; ?>"> </p> <p> <label>Email address:</label> <input class="text" type="text" name="email" value="<?php print $email; ?>"> </p> <p> <label>Category:</label> <select name="category"> <option value="general">General Inquires</option> <option value="problem">Report a Problem</option> <option value="team">Team Application</option> <option value="other">Other</option> </select> </p> <p> <label>Message:</label> <textarea name="text"><?php print $text; ?></textarea> </p> <input type="submit" class="submit" value="Send!" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/201296-contact-form-help/#findComment-1056098 Share on other sites More sharing options...
zimmo Posted May 10, 2010 Share Posted May 10, 2010 Just so you know you had these in the wrong order if(mail($myemail, $subject, $header, $message)) As you can see by my change. Also, dont forget to pre-propagate the drop down as well so they dont have to reselect that if they make a mistake. Link to comment https://forums.phpfreaks.com/topic/201296-contact-form-help/#findComment-1056103 Share on other sites More sharing options...
Sebolains Posted May 10, 2010 Author Share Posted May 10, 2010 Hi... For some reason your code is still not working for me :'( I have no idea why, but it keeps saying there was a problem. Maybe it has something to do with the host? I don't know... Do you know if there's something else I have to change to get it working? Thanks for your help!!! Link to comment https://forums.phpfreaks.com/topic/201296-contact-form-help/#findComment-1056115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.