taokore Posted July 1, 2010 Share Posted July 1, 2010 Hey guys, I have a very short script that I am using to to just pull info from an email form. I am fluent in html/css but the php here that is causing me problems. Could I trouble anyone to take a quick look for errors? The script was taken from an online source and slightly altered. <?php if(isset($_POST['email'])) { $email_to = "[email protected]"; $email_subject = "Inquiry"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['website']) || !isset($_POST['project'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['website']; // not required $comments = $_POST['project']; // 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,$name)) { $error_message .= 'The name you entered does not appear to be valid.<br />'; } if(strlen($project) < 2) { $error_message .= 'The project description you entered do not appear to be valid.<br />'; } $string_exp = "^[0-9 .-]+$"; if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Website: ".clean_string($website)."\n"; $email_message .= "Project: ".clean_string($project)."\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); ?> Thank you for contacting us. We will be get back to you very soon. <? } ?> The form itself is set up fine with method="post' and action="send_form_email.php", but I am doing something wrong here. Any suggestions? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/ Share on other sites More sharing options...
mrMarcus Posted July 1, 2010 Share Posted July 1, 2010 What are the "issues"? What is happening? Is the script running? Are you getting errors? If so, what are they? If you run the script in its original state, does it work? What did you change? Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079861 Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2010 Share Posted July 1, 2010 A) Like mrMarcus just wrote, you did not provide any help as to what it did do, and B) You might want to read the following thread because it appears to be the same basic code - http://www.phpfreaks.com/forums/index.php/topic,302757.0.html Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079862 Share on other sites More sharing options...
taokore Posted July 1, 2010 Author Share Posted July 1, 2010 Wow, I feel like kind of an idiot - not actually writing the problem down. Winner here. Anyhow the error it says is: "We are very sorry, but there were error(s) found with the form you submitted. These errors appear below. We are sorry, but there appears to be a problem with the form you submitted. Please go back and fix these errors." Now, I must tell you - I literally know near nothing of php or how the language operates. So I don't know if or how to tell the script is running, but I ran the code in its original state (taken from http://www.freecontactform.com/email_form.php), and it sent through just fine. I am really clueless here on what is going wrong in my version. However, I am sure I can understand what is what just by using common sense if someone were to point out an error they see. To see it run live, you can use the Contact Us form at www.omni-flux.com/progress/. From there the form action just uses send_form_email.php which is the code from my OP. I modified the script to use 4 items with different names for each "event" (terminology?) or text fields instead of the 5 originally written in there. That may be a reason it's not working. Is this enough info? Thank you for your replies so far! Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079980 Share on other sites More sharing options...
taokore Posted July 1, 2010 Author Share Posted July 1, 2010 Oh, I also read that other post but could not discern anything of use from it. This may just be to my own lack of knowledge. Thank you though! Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079981 Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2010 Share Posted July 1, 2010 That it prints out something means that the <? tag is not a problem (you should change it to <?php anyway.) The error message it does print is 'We are sorry, but there appears to be a problem with the form you submitted.' That implies that not all of your form field are named as indicated in the php code, because they would be set, even if empty. Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079984 Share on other sites More sharing options...
taokore Posted July 1, 2010 Author Share Posted July 1, 2010 There we go! I didn't even think of the fact that I used my own markup and the naming was not completely consistent with the script. Thank you very much PFMaBiSmAd! It works great now! Very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/#findComment-1079993 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.