tezzo Posted January 31, 2014 Share Posted January 31, 2014 (edited) <?php if(isset($_POST['txtEmail'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "xyz@abc.com"; $email_subject = "Subject"; $email_from = "abc@xyz.com"; 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."; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['txtName']) || !isset($_POST['txtEmail']) || !isset($_POST['txtAddress']) || !isset($_POST['txtContact']) || !isset($_POST['txtUpload'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['txtName']; // required $email = $_POST['txtEmail']; // required $address = $_POST['txtAddress']; // required $contact = $_POST['txtContact']; // not required $upload = $_POST['txtUpload']; // required $email_message = "Form Details are below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($name)."\n\n"; $email_message .= "Address: ".clean_string($address)."\n\n"; $email_message .= "Email ID: ".clean_string($email)."\n\n"; $email_message .= "Contact No.: ".clean_string($contact)."\n\n"; $email_message .= "File: ".clean_string($upload)."\n\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> i am a rookie in php I got 2 problems 1) I am not able to insert a code for file upload in the above code. 2) In other type of form (with different textfields).i have a text (it is like a disclaimer) in the html form which i want it in email too. Edited February 24, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/ Share on other sites More sharing options...
Ch0cu3r Posted January 31, 2014 Share Posted January 31, 2014 1) I am not able to insert a code for file upload in the above code. See Handling file uploads in the PHP manual 2) In other type of form (with different textfields).i have a text (it is like a disclaimer) in the html form which i want it in email too. Copy the disclaimer text and assign it to a variable, and then concatenate that onto $email_message $diclaimerText = 'your disclaimer'; ... $email_message .= "--------------------------------\n\n$disclaimerText"; // append disclaimer to email Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467201 Share on other sites More sharing options...
tezzo Posted February 1, 2014 Author Share Posted February 1, 2014 i am unable to understand where to insert the code...in php i only know how to replace the existing textfield names with my textfields name and email id...so you can imagine my knowledge in php.......would you please show to where do i add the code.....Sorry for troubles Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467339 Share on other sites More sharing options...
Barand Posted February 1, 2014 Share Posted February 1, 2014 You are already constructing $email_message and you want the disclaimer to go at the end of it. Also, there is no point in adding the disclaimer after the email has been sent. So, have a look at your code and think about where a suitable place would be. Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467340 Share on other sites More sharing options...
tezzo Posted February 3, 2014 Author Share Posted February 3, 2014 well....Client wants the disclaimer also in the email....i dont want at the end of it........it is the middle.....but this is not the script fot that......i just have to edit the textfield name....i dont know what code should i put in my script Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467505 Share on other sites More sharing options...
Ch0cu3r Posted February 3, 2014 Share Posted February 3, 2014 .Client wants the disclaimer also in the email....i dont want at the end of it........it is the middle This code here sets the text for the body of the email $email_message .= "Full Name: ".clean_string($name)."\n\n"; $email_message .= "Address: ".clean_string($address)."\n\n"; $email_message .= "Email ID: ".clean_string($email)."\n\n"; $email_message .= "Contact No.: ".clean_string($contact)."\n\n"; $email_message .= "File: ".clean_string($upload)."\n\n"; Place $email_message .= "your email disclaimer text\n\n"; Where the client wants the disclaimer to appear. So if it is after the Address, then add the line of code above after the Address line. .but this is not the script fot that......i just have to edit the textfield name....i dont know what code should i put in my script What? I do not understand. Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467524 Share on other sites More sharing options...
tezzo Posted February 4, 2014 Author Share Posted February 4, 2014 heyy...gr8....its working....i was evn inserting the disclaimer in the codes above set of codes....hence it was not working...problem 2 solved .....but 1 remains Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467662 Share on other sites More sharing options...
Ch0cu3r Posted February 4, 2014 Share Posted February 4, 2014 (edited) problem 2 solved .....but 1 remains What problem remains? Edited February 4, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467692 Share on other sites More sharing options...
tezzo Posted February 5, 2014 Author Share Posted February 5, 2014 i want to insert code for file upload..........i don't want the validation....just the code Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467797 Share on other sites More sharing options...
Ch0cu3r Posted February 5, 2014 Share Posted February 5, 2014 The link I gave in post #2 gives example codes for file uploads. What have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1467814 Share on other sites More sharing options...
tezzo Posted February 24, 2014 Author Share Posted February 24, 2014 i want to insert validations for radio buttons in the above form........(I tried many scripts but no luck) below is my html code <form> <input type="radio" name="txtRadio" value="Purchase"> Purchase <input type="radio" name="txtRadio" value="Sell"> Sell </form> Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1470414 Share on other sites More sharing options...
Ch0cu3r Posted February 24, 2014 Share Posted February 24, 2014 (edited) You just need to check to see what value $_POST['txtRadio'] holds when the form is submitted if(isset($_POST['txtRadio'])) { if($_POST['txtRadio'] == 'Purchase') { // the Purchase radio button was selected } elseif($_POST['txtRadio'] == 'Sell') { // the Sell radio button was selected } else { // the user submitted an unexpected value? } } else { // the user did not select a radio button } Edited February 24, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1470419 Share on other sites More sharing options...
tezzo Posted April 7, 2014 Author Share Posted April 7, 2014 can u tell me how can i add BCC in the above script......i tried a few ways...like 1) $headers .= "\r\nBcc: her@$herdomain\r\n\r\n"; 2) $email_bcc = "xyz@abc.com"; (top half after $email_to and then adding it at the bottom half 'Bcc: '$email_bcc."\r\n" . after 'Reply-To: '.$email."\r\n" .) I am getting syntax error for 2nd method. Not able to understand whats wrong Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1475233 Share on other sites More sharing options...
Ch0cu3r Posted April 7, 2014 Share Posted April 7, 2014 (edited) Before this line 'Reply-To: '.$email."\r\n" . add "Bcc: her@$herdomain\r\n" . Edited April 7, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1475236 Share on other sites More sharing options...
tezzo Posted May 6, 2014 Author Share Posted May 6, 2014 hey...thank you so much for your reply...you are a genius.....(Sorry for late comment)... I am stuck again.... on submitting the form......i want to show the error and successful message on the same page.....by hiding the contact form..... e.g Feedback form on the homepage of http://www.flipkart.com/ (Don't worry about the animation) Quote Link to comment https://forums.phpfreaks.com/topic/285821-need-help-in-php-form/#findComment-1478351 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.