Iluvatar13 Posted March 9, 2010 Share Posted March 9, 2010 I'm trying to set up a php email form for a website I did for work and have ran into a snag. After going through a few different options I found (as I'm still too new to php to code one from scratch) this was the one that seemed best suited for the job. So I went through and edited it as needed and it seems like it should be working, but the submit button brings me to a "not found" page while trying to access mailer.php. I've tried without having the Submit variables as well to the same conclusion. Any help on what I did wrong would be appreciated, the code and link are posted below. http://thegrowframe.com/retail.html <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "ainurdesign@gmail.com"; $email_subject = "GrowFrame Retailer Form"; function died($error) { // your error code can go here echo "We are sorry, but one or more errors were found with the form you submitted."; echo $error."<br /><br />"; echo "Please fill in the missing requirements and try again.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['Company']) || !isset($_POST['Contact']) || !isset($_POST['Email']) || !isset($_POST['Phone']) || !isset($_POST['Street']) || !isset($_POST['City']) || !isset($_POST['State']) || !isset($_POST['Zip']) || !isset($_POST['Interest']) || !isset($_POST['Agree']) || !isset($_POST['Submit'])) { died('We are sorry, but one or more errors were found with the form you submitted.'); } $company = $_POST['Company']; // required $contact = $_POST['Contact']; // required $email_from = $_POST['Email']; // required $phone = $_POST['Phone']; // required $street = $_POST['Street']; // required $city = $_POST['City']; // required $state = $_POST['State']; // required $zip = $_POST['Zip']; // required $interest = $_POST['Interest']; // required $license = $_POST['License']; // not required $business = $_POST['Business']; // not required $url = $_POST['URL']; // not required $comments = $_POST['Comments']; // not required $agree = $_POST['Agree']; // required $submit = $_POST['Submit']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$company)) { $error_message .= 'The Company Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$contact)) { $error_message .= 'The Contact Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$city)) { $error_message .= 'The City Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$state)) { $error_message .= 'The State Name you entered does not appear to be valid.<br />'; } // if(strlen($comments) < 2) { // $error_message .= 'The Comments you entered do not appear to be valid.<br />'; // } $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$phone)) { $error_message .= 'The Telphone Number you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$zip)) { $error_message .= 'The Zip Code you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Retailer information is as follows;\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Company Name: ".clean_string($company)."\n"; $email_message .= "Contact Name: ".clean_string($contact)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Phone Number: ".clean_string($phone)."\n"; $email_message .= "Street Address: ".clean_string($street)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "State: ".clean_string($state)."\n"; $email_message .= "Zip: ".clean_string($zip)."\n"; $email_message .= "Interested in Drop or Wholesale: ".clean_string($interest)."\n"; $email_message .= "Business License Number: ".clean_string($licnese)."\n"; $email_message .= "Business Type: ".clean_string($business)."\n"; $email_message .= "Store URL: ".clean_string($url)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "Agree: ".clean_string($agree)."\n"; $email_message .= "Submit: ".clean_string($submit)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <div class='submitted'>We will review the information that you submitted, and reply soon with the GrowFrame<span class='reg'>®</span> price and term sheet. If you have any immediate questions, please feel free to call our Sales Manager, Traci Elliott, at 1 (805) 407-3471.</div> <? } ?> Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted March 9, 2010 Share Posted March 9, 2010 I can only assume the mailer.php not being linked to properly. You're form "action" is here: http://thegrowframe.com/public_html/public/mailer.php You need to make sure that is where the mailer.php is on the server - which I doubt considering the structure. Change the html and look for the <form action=" part for your contact form. Change that to the correct address and it should work. Hope that helps. Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Willing to guess if you change the form action to "/public/mailer.php" you'll be golden Quote Link to comment Share on other sites More sharing options...
Iluvatar13 Posted March 9, 2010 Author Share Posted March 9, 2010 Ok I was blind and didn't notice the link was wrong lol, now that that's fixed it goes to the mailer.php as a blank page instead of sending the email or returning an error. Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Alright, well that's a good start! At this point you want to start debugging...make sure that error reporting is turned on, and see if anything is getting spit back at you. this looks like it could be one (of many) places the application is failing die() is a php function, but I don't know about died() died('We are sorry, but one or more errors were found with the form you submitted.'); Quote Link to comment Share on other sites More sharing options...
Iluvatar13 Posted March 9, 2010 Author Share Posted March 9, 2010 Hrm, I tried changing died to die (I thought that looked out of place) but still the blank page. I'm just not sure what to look for, this is the first time I've tried to make something in php outside of html edits on a php page. Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Well, with PHP if you are getting a blank page it's one of two things. #1 - Everything ran awesomely, but you didn't echo anything out to the screen (this is pretty rare ;0) #2 - You had an error, and PHP shit it's pants but isn't telling you because error reporting is turned off. In production environments (where your code will live in the open public) you want error reporting turned off so people can't see anything important about your system or application. In your dev environment you want PHP to complain if it farts and it doesn't like it You can achieve this one of two ways #1 - Set up error reporting in your php ini or #2 - Put this at the top of your page ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); Then try again and tell me what it says Also, try typing something like echo "page loaded"; in your mailer.php script so at least THAT should show up (so you can verify that your form is pointing to the right file) Quote Link to comment Share on other sites More sharing options...
Iluvatar13 Posted March 10, 2010 Author Share Posted March 10, 2010 Was that supposed to go on my html page? It didn't make anything new show up on the blank one for mailer.php, I put it outside the php tags just to see if it would pop up and it did, so it's directing to the page properly at least. Quote Link to comment Share on other sites More sharing options...
ReeceSayer Posted March 10, 2010 Share Posted March 10, 2010 Was that supposed to go on my html page? It didn't make anything new show up on the blank one for mailer.php, I put it outside the php tags just to see if it would pop up and it did, so it's directing to the page properly at least. I believe that the code should only go at the top of .php files to see what errors (if any) are being thrown because its a php function. Other than that i can only suggest that you check XAMPP (if thats the web server you use) is running, i know its simple but i've done this before (but i'm new to this too lol). Sorry i can't be any more help i'm pretty new to this too Quote Link to comment Share on other sites More sharing options...
Iluvatar13 Posted March 10, 2010 Author Share Posted March 10, 2010 Unfortunately the only access I have to the server is ftp. :/ The guy that has all the access isn't replying to my email atm so I'm trying to figure it out on here. Though he did say php was supported and on. Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 10, 2010 Share Posted March 10, 2010 It should be at the top of your mailer.php file. When you set the form action in your html form it forwards you to that particular php page and gets processed. (mailer.php) what you want to do is make sure that file is being called (your url in the address bar should show mailer.php), and that the errors are being shown. Put that at the top and you should have some better luck (top of the php file) Quote Link to comment Share on other sites More sharing options...
Iluvatar13 Posted March 10, 2010 Author Share Posted March 10, 2010 Yeah that's what I tried, I put it at the top (both above and below the <?php tag) and it didn't make any errors show. Just showed as text outside the tag and still blank inside the tag. :/ 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.