Ricklord Posted July 26, 2006 Share Posted July 26, 2006 Hi peeps, I don't usually ask questions in forums, but this one has been bugging me for the last few hours and ive read so many tutorials on how to do the contact us form but it just isnt working properly. please view my html side at: http://www.creativecogs.co.uk/testform/contact_us.html The script is available at: http://www.creativecogs.co.uk/testform/contact.phps I dont know why but this form just wont work it was working at the strt when i tested it but as i have put it into my actual site and added a few check boxes it doesnt work. When the form is submitted it just goes to the error text i have put into the php script. Im not a coder so please go easy on me. Ive tried to put different parts out of different scripts into one which is why it might not be working.If anyone can help i would be most gratefulCheersRick Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 This is because you havn't given your submit button a name.Change:[code]<input value="Submit Comments" type="submit"> [/code]to[code]<input value="Submit Comments" name="submit" type="submit">[/code]Also I would recommend you to validate user input (your post variables). As your email script will be prone to spam! Malicous users will be able to send multiple emails in one go! Also you font validate for valid email addresses. Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64156 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 sweet!!! thanks!!!i did look at the but becuase it was going through to the contact.php page thought the submit button was working fine and assumed it was a problem with the php script. added <<<<how do you mean vaildate the email address, is this a few lines of code i need to add?>>>>>>But thanks, its working now. How do i get the email address entered to come up as the sender in my inbox, it just says the email is from creativecogs.co.uk???and finally how do i get it to go to a thankyou.html page after the script is executed instead of the echo command???thanks again for spotting that submit error and so quickly. Rick :):):):) Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64163 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 You'll be best of searching for form validation tutorials. For your setup I would recommend you to do javascript form validation and possibaly PHP form validation too just incase the user has javascript turned off. SO fi you search for form validation tutorials with google you'll get a ton of results. Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64177 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 Ok will do a search for the validator. Any idea on how to forward onto a html page rather than the echo command i am using? I have searched for this but had no look, dont even know if im typing the right thing into google.Also having the email address entered come through as the sender in my inbox?Cheers Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64181 Share on other sites More sharing options...
kenrbnsn Posted July 26, 2006 Share Posted July 26, 2006 I would recommend always doing validation via PHP and don't depend on Javascript. Spambots that will try to use your form for malicious activity will not use your form, but will send data directly to your processing script, thereby negating any Javascript validation being done on the client side.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64191 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Use header:[code]header("Location: thanx.html");[/code]Make sure there is no output before the use of this function.To show who sent the email you'll want to send additional headers (4th parameter for mail function). A bit like this:[code]$header = "From: {$name}<{$email_field}>"; mail($to, $subject, $body, $header);[/code]This where your validation is most important! As your contact form is now prone to spam! Now you are using custom headers! Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64195 Share on other sites More sharing options...
jworisek Posted July 26, 2006 Share Posted July 26, 2006 slightly off topic, but are the exploits of mail scripts only possible if you place user input into the header? Personally I don't put the users email address as From:. I just put our website so that we know it was submitted from the web and then the users email is listed in the body. Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64204 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 So you dont want to put the users name and email in the From bit? Just your website? If thats the case you can do this:[code]$header = "From: mysite.com<[email protected]>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64210 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 Hi Again, got the header in the right place and now forwarding on to a html page so thanks. With the from field it is just coming up blank now any suggestions? or do i need to incorporate a validator before it will work?this is my script now[code]<?php header("Location: http://www.creativecogs.co.uk/thankyou.html");if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Web Design Online enquiry"; $header = "From: {$name}<{$email_field}>";$name_field = $_POST['name']; $email_field = $_POST['email'];$telephone_field = $_POST['telephone']; $message = $_POST['message']; foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $body = "From: $name_field\n E-Mail: $email_field\n Telephone: $telephone_field\n $check_msg Option: $option\n Message: $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $header); } else { echo "failed please try again"; } ?> [/code]CheersRick Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64218 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 You are still using the old header code:[code]$header = "From: {$name}<{$email_field}>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64219 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 just read the other 2 posts about having the from field as the email address or setting it to show the web address. Reason i want it to show me the email address is so i can have an autoresponder going from my webserver. dont know if this is possible with php but just thought if i can get the email address to show up then my auto responder on my web server can do this for me. Rick Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64221 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 ok sorry if im being 100% thick which i probably am but ive added the [code]$header = "From: {$name}<{$email_field}>";[/code]it might be in the worng place though????does it need to be above the $to and $subject or do i need to change these to [code]$header = "To: [email protected]>"$header = "Subject: [email protected]>"[/code]I don't understand php that well so thats probably wrong. could you let me know where im going wrong? Rick Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64236 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Your header var is in the wrong place, place it after the $message variable, like so:[code]$message = $_POST['message']; $header = "From: {$name}<{$email_field}>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64246 Share on other sites More sharing options...
Ricklord Posted July 26, 2006 Author Share Posted July 26, 2006 WKD, thanks again :):):) Now ill look at some tutorials for validation. Thanks again Rick Quote Link to comment https://forums.phpfreaks.com/topic/15714-contact-us-form/#findComment-64250 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.