robolist Posted August 22, 2010 Share Posted August 22, 2010 Hey guys, I really hope someone can help me out here. I have been working on my new website all week and am now almost finished. Just need to complete the contact page and touch up a few things... I really dont know php at all to be honest and just found a code somewhere on the net to help me. Heres my problem I have finally got the form to work but i am not recieving the correct data. I only get the email add, subject and messge. I am not getting the name of the sender.. also i really want to add a website field to the code because i do have that on the contact form... please can someone tell me where i am going wrong? the following is the php code i am using... <?php // Contact subject $subject ="Website enquiry"; // Details $message=$_POST[detail]; // Mail of sender $mail_from=$_POST[customer_mail]; // From $header="from: $name <$mail_from>"; // Enter your email address $to ='robin@rdosolutions.com'; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> please help me.. i am hoping to put the site live tomorrow... many thanks in advance.. rob Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/ Share on other sites More sharing options...
MatthewJ Posted August 22, 2010 Share Posted August 22, 2010 Your post values need to be quoted $_POST['customer_detail'] instead of $_POST[customer_detail] Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1102340 Share on other sites More sharing options...
kenrbnsn Posted August 22, 2010 Share Posted August 22, 2010 No, they will work without the quotes. Please post your form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1102341 Share on other sites More sharing options...
Spriced Posted August 22, 2010 Share Posted August 22, 2010 Here's what I use on my website: <form id="contact-form" action="send-mail.php" method="post"> <label for="name">Name</label> <input type="text" name="name" id="name" /> <label for="email">Email</label> <input type="text" name="email" id="email" /> <label for="message">Message</label> <textarea name="message" id="message" rows="5" cols="35"></textarea> <input type="submit" class="submit" value="Send" /> </form> <?php function validate_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } if (isset($_POST['name'])) { // The form was submitted $n = trim(stripslashes(strip_tags($_POST['name']))); $e = trim(stripslashes(strip_tags($_POST['email']))); $m = trim(stripslashes(strip_tags($_POST['message']))); $eol = "\r\n"; if (validate_email($e) && !empty($n) && !empty($m)) { // Form was filled in correctly $s = "Enquiry from $n"; // Subject $t = "YOUR EMAIL ADDRESS"; // Your email address $headers.= "To: YOUR NAME <$t>".$eol; $headers.= "From: $n <$e>".$eol; if(mail($t, $s, $m, $headers)) { // Everything went fine echo '<p class="response-good">You email has been sent, thanks.</p>'; } else { // Mail function failed echo '<p class="response-bad">There was a problem sending the email, please try again later.</p>'; } } else { // Email didn't validate or name or message fields were empty after processing echo '<p class="response-bad">Please fill out all fields & ensure that your email is valid.</p>'; } } else { // Form wasn't filled out echo '<p class="response-bad">Please fill out the form.</p>'; } ?> You can easily modify it to your needs. Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1102350 Share on other sites More sharing options...
robolist Posted August 22, 2010 Author Share Posted August 22, 2010 Thanks guys.. yeah i just want a very simple php script.. no need for validation or anything.. here is my form <form id="myform" action="send_contact.php" method="post" enctype="multipart/form-data"> <div> <div class="field"> <label for="name" >Name</label> <input class="inputfield textfield" name="name" type="text" /> </div> <div class="field"> <label for="customer_mail" >E-mail</label> <input class="inputfield textfield" name="customer_mail" type="text" /> </div> <div class="field"> <label for="website" >Website</label> <input class="inputfield textfield" name="website" type="text" /> </div> <div class="field area"> <label for="detail" >Details</label> <textarea class="inputfield textarea1" name="detail" ></textarea> </div> </div> <!--div class="clear"></div--> <input class="submitbutton" type="submit" value="Submit" name="Submit"/> </form> and again here is my script <?php // Contact subject $subject ="Website enquiry"; // Details $message=$_POST[detail]; // Mail of sender $mail_from=$_POST[customer_mail]; // From $header="from: $name <$mail_from>"; // Enter your email address $to ='robin@rdosolutions.com'; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> as i said it s working except the name doesnt get sent and i also want to add the website field.. thanks in advance.. Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1102363 Share on other sites More sharing options...
jcbones Posted August 22, 2010 Share Posted August 22, 2010 no need for validation or anything.. Oh, you don't know how bad you need validation. Try something like: <?php // Contact subject $subject ="Website enquiry"; // Details $message=trim(strip_tags($_POST['detail'])); $name = trim(strip_tags($_POST['name'])); $webste = trim(strip_tags($_POST['website'])); // Mail of sender $mail_from=trim(strip_tags($_POST['customer_mail'])); // From $header="from: $name <$mail_from>"; // Enter your email address $to ='robin@rdosolutions.com'; $message = $name . PHP_EOL . $website . PHP_EOL . $mail_from . PHP_EOL . $message; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1102498 Share on other sites More sharing options...
robolist Posted August 24, 2010 Author Share Posted August 24, 2010 Hey guys thanks so much for all your help... jcbones thank you so much... you have solved my problem... yes i am sure i will need validation at some point but my site doesnt get so many visiters just yet.. thanks again for all your help... Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103046 Share on other sites More sharing options...
robolist Posted August 24, 2010 Author Share Posted August 24, 2010 One more thing actually.. If i want to direct it to one of my pages if processed successfully of not. so i would design another two pages for this.. but what code do i use? many thanks n advance.. rob Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103050 Share on other sites More sharing options...
robolist Posted August 24, 2010 Author Share Posted August 24, 2010 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103133 Share on other sites More sharing options...
Pikachu2000 Posted August 24, 2010 Share Posted August 24, 2010 Instead of simply echoing the success/failure messages, you can use a header() redirect at that point. Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103141 Share on other sites More sharing options...
robolist Posted August 24, 2010 Author Share Posted August 24, 2010 Instead of simply echoing the success/failure messages, you can use a header() redirect at that point. Hi Pikachu, Thanks for the advice on that. But I have no idea how to do what you just said.. hahaha.. So sorry but I am very novice with php... do you think you would be able to just give me the code for that? I would be very grateful. Cheers Rob Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103156 Share on other sites More sharing options...
Pikachu2000 Posted August 24, 2010 Share Posted August 24, 2010 Here's a link to the PHP manual for the header() function. Look it over, and give it a try. If you have any problems, post them here. Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103168 Share on other sites More sharing options...
robolist Posted August 24, 2010 Author Share Posted August 24, 2010 Dear all concerned, I would like to thank each and every one of you who have so kindly given me your time and knowledge in helping me with my contact form. Thanks to all of you it is now finally complete and in working order. Please feel free to browse through my website and give me your professional opinions on my design and content. All comments are much appreciated. http://www.rdosolutions.com Many thanks Rob Quote Link to comment https://forums.phpfreaks.com/topic/211420-contact-form-driving-me-crazy/#findComment-1103219 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.