PHP - Complete Noob Needs A Guidance On Very Basic Contact Form
Gday,
I'm trying to add a contact form on my site using a PHP script I downloaded from the web. I have tweaked the script, but I have never used PHP before and haven't got the time to learn it yet. Could someone please help me to get this working, I have added a subject drop down field that I would like to add validation to force the user to choose one, and I'd like the subject they choose to appear in the subject field of the resulting email. Once the PHP script has run and the email has been sent I'd like the text at the bottom to appear on the original page. At the moment when i click submit it just goes to the php page and shows three lines of the error message text. Here is the relevant code: This form is placed within a static html page: Code: [Select] <form name="contactform" method="post" action="send_form_email.php" style="text-align:left;"> <label for="first_name">First name <span class="red">*</span></label> <input name="first_name" type="text" value="please enter your first name" size="30" maxlength="75" onclick="document.contactform.first_name.value='';" /> <br/> <label for="last_name">Last name <span class="red">*</span></label> <input name="last_name" type="text" value="please enter your last name" size="30" maxlength="75" onclick="document.contactform.last_name.value='';" /> <br/> <label for="email" style="margin-right:32px;">Email <span class="red">*</span></label> <input name="email" type="text" value="please enter your email address" size="30" maxlength="75" onclick="document.contactform.email.value='';" /> <br/> <label for="phone_number" style="margin-right:34px;">Phone</label> <input name="phone_number" type="text" value="please enter your phone number" size="30" maxlength="75" onclick="document.contactform.phone_number.value='';" /> <br/> <label for="email_subject" style="margin-right:19px;">Subject <span class="red">*</span></label> <select name="email_subject" style="margin-bottom:10px;"> <option value="Choose one">Choose one</option> <option value="Lost my password">Lost my password</option> <option value="Gardening advice">Gardening advice</option> <option value="Order status">Order status</option> <option value="Web feedback">Web feedback</option> <option value="Customer Service">Customer Service</option> <option value="Product feedback">Product feedback</option> <option value="Other">Other</option> </select> <br/> <label for="comments">Queries/Comments <span class="red">*</span></label> <textarea rows="10" cols="50" wrap="virtual" name="comments" onclick="document.contactform.comments.value='';" style="margin-bottom:5px;">Please type your query or comments here</textarea> <input type="submit" value="Submit" /> </form> and here is the seperate php script that is used: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "johnc@diggers.com.au"; $email_subject = $_REQUEST['email_subject']; 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['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['email_subject']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $telephone = $_POST['email_subject']; // required $comments = $_POST['comments']; // 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,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last 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,$telephone)) { $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />'; } 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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\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 --> Thank you for contacting us. We will be in touch within 72 hours of the next working day. <? } ?> Any help on how to get this going would be greatly appreciated, thanks Similar TutorialsHi. I'm currently taking a class in PhP and I'm having issues getting my code to work. I "borrowed" part of the code from elsewhere (but I fully understand each line - which is really the point of learning) I'm hoping a second set of eyes might help on what's wrong: I'm running Wamp Server v2.0 on my local PC to test the scripts... I'm sure I'm probably going to have more then just this error with the script, but it's hard to move forward when you're stuck spinning your wheels. Any help would be greatly appreciated... and any suggestions as to a better way to approach this would be welcome as well. I am here to learn after all Here's the error I'm getting: Notice: Undefined variable: fname in C:\Web Server\wamp\www\daystoxmas.php on line 8 Please return to the main page and enter your First Name. Here's the HTML Code: <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Days to Christmas Form</title> </head> <body> <div><p><h1>Days to Christmas Form</h1></p> <p>- Programmed by: Michael Custance</p> <form action="daystoxmas.php" method="post"> <p>First Name: </select><input type="text" name="fname" size="20" /></p> <p>Last Name: </select><input type="text" name="lname" size="20" /></p> <p>E-mail Address: <input type="text" name="email" size=20 /></p> For Christmas gift ideas, click here! <input type="submit" name="Submit" value="Christmas Gift Page" /> </form> </body> </html> And here's the PhP Form: <HTML> <HEAD> <TITLE>daystoxmas.php</TITLE></HEAD> <BODY> <?php if ($fname) { print ("Good "); if (date("A") == "AM") { print ("morning, "); } elseif ( (date("H") >= 12 ) and (date("H") < 18) ) { print ("afternoon, "); } else { print ("evening, "); } print ("$FirstName<P>"); $Christmas = mktime(0, 0, 0, 12, 25, date('Y')); $today = mktime(); $seconds_to_christmas = $Christmas - $today; $days_to_christmas = $seconds_to_christmas / 86400; $days_to_christmas = floor($days_to_christmas); $temp_remainder = $seconds_to_christmas - ($days_to_christmas * 86400); $hours = floor($temp_remainder / 3600); $temp_remainder = $temp_remainder - ($hours * 3600); $minutes = round($temp_remainder / 60, 0); echo '<p>There is ' . $days_to_christmas . ' days and ' . $hours . ' hours and ' . $minutes . ' minutes until Christmas</p>'; } else { print ("Please return to the main page and enter your First Name."); } ?> </BODY> </HTML> Helo - Total newbie here, so please keep that in mind. I'd really appreciate some wisdom from someone here as to how you would improve this form: <?php $email = $_POST['email']; $message = $_REQUEST['message']; $message = $_POST['date']; $message .= $_POST['location']; $message .= $_POST ['comments']; mail( "testing@gmail.com, 5602346789@metropcs.com", "General Inquiry", $message, "From: $email" ); header( "Location: thankyou.html" ); ?> *******************************html****************************** <HEAD><title>Hi</title<HEAD><BODY BGCOLOR="lightgray"><br><br><center><br><br><form method="post" action="sendmail2.php"><table cellspacing="5" cellpadding="5" border="0"> <tr> <td valign="top"><font face="arial"> <strong>Contact email:</strong><br> </td> <td valign="top"><font face="arial"> <input type="text" name="email" size="50" value="" /> </td> </tr><tr><td valign="top"><font face="arial"> <strong>Date:</strong> </td> <td valign="top"><font face="arial"> <input type="text" name="date" size="50" value="" /> </td> </tr> <tr><td valign="top"><font face="arial"> <strong>location:</strong><br> </td> <td valign="top"> <input type="text" name="location" size="50" value="" /> </td> </tr> <tr> <td valign="top"><font face="arial"> <strong>Comments:</strong><br><font color="black"> </td> <td valign="top"> <textarea name="comments" rows="6" cols="40"></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </table> </form></center></body> After many hours of playing and help from here and other places I have managed to figure out how to login to a particular website, then submit a form that you have to be logged in to get to using cURL. The reason behind me doing this is because my client needs to submit about 40 forms a day per website, there are 3 sites, so that is 120 forms. I am hoping that I can reduce this to only 40 forms, and once they complete one they can just submit it to the other 2 without retyping or copy pasting every field. This is what I have so far, a problem is that I can not give the website username and password as it is a paid for site that my client has entrusted me with. I can tell you that the site is careerjunction.co.za and within the recruiters section. Now this site works a little different, first off there is no remember me on the login area, and it uses cookies to let me get around. If I login, it gives me a cookie, if I try login again from another computer, it gives an error and tells me I have to logout first, with a click here to logout of the other session. If I login and then click logout, a javascript window asks me if I am sure and then logs me out after pressing yes. Every month they make you change your password, and have a form come up saying old pass, new pass, repeat new pass. The script below works only if I am logged out, so this logs in then shows the form, problem is I can not do this a second time 2 days later because I have to logout first, and I can not use it if the account is already logged in. I would like to adjust the script to logout first, then login and show the form. Code: [Select] //create a file called cookie.txt and place in site root with perms at 777 first. //logout page is "http://v1.careerjunction.co.za/usr/mltses.asp?" curl_login("http://v1.careerjunction.co.za/rec/acc/logfrmupd.asp", "Username=example&Password=example", "", "false"); echo curl_grab_page("http://v1.careerjunction.co.za/rec/my/job/jobfrm.asp?recno=-1&p=1&HideTemp=1", "", "false"); function curl_login($url,$data,$proxy,$proxydata){ $fp = fopen("cookie.txt", "w"); fclose($fp); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($login, CURLOPT_TIMEOUT, 40); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'true') { curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($login, CURLOPT_PROXY, $proxy); } curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_HEADER, TRUE); curl_setopt($login, CURLOPT_USERAGENT, $SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); curl_setopt($login, CURLOPT_POSTFIELDS, $data); ob_start(); //prevent any output return curl_exec ($login); //execute the curl command ob_end_clean(); //stop preventing output curl_close ($login); unset($login); } function curl_grab_page($site,$proxy,$proxystatus){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'true') { curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($login, CURLOPT_PROXY, $proxy); } curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($ch, CURLOPT_URL, $site); ob_start(); //prevent any output return curl_exec ($ch); //execute the curl command ob_end_clean(); //stop preventing output curl_close ($ch); } The end result I would like to have is this My customer needs to have a form on their own website that once completed needs to go onto their website database, this seems simple enough for me to achieve. Then they need to be able to complete a very similar form on three other websites without logging into each and filling out the form all over again. So I would like it that once they have their own form completed, they could click a button and that would submit all the data to the relative site, therefore they would have 3 buttons one for each site they want to submit data to. I am only dealing with the first site at the moment so I have a very long way to go, and this does not even account for if they want to edit an existing form or anything like that. Whew I think I have bitten off a little more than I bargained for. Maybe a curl / php expert from here would like to PM me and we can work out some form of remuneration to help me complete this project, I have the entire site designed already and this is just part of the backend of the site. Let me know what sort of $$dolars you think it would cost to help please. I apologize in advance, I know pretty much nothing about PHP - don't hate me, please! But I'm working on a form mailer, and it functions, but what I don't like is it leaves all the text fields, blank or not, in my email, which makes it difficult for my client to read, so theres a long list of txt field1: another text field: blah blah: all the way down the email - and I want it gone! haha. I've researched how to do this, but basically, I have no idea how to implement it into my code and don't have time right now to up and learn PHP. My code is as follows: Code: [Select] <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> IT was a very simple copy-paste form, but I have no idea what on earth I'm doing. If anyone has any ideas I would GREATLY appriciate the help! Thanks! -Austin Hello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hi all, I am currenlty coding up PHP validation for a contact form and as I know barely any PHP i have been following tutorials and copying code. I have a series of checkboxes which emails out the various products that the user wants. It all works now except that it does not re-direct to a thank you page now and outputs this error at the top of the page. Warning: Invalid argument supplied for foreach() in /home2/xxxxxxxx/public_html/client/contact.php on line 17 Below is the code for the PHP and form, any help would be greatly appreciated. Thank you! Code: [Select] <?php if (isset($_POST['submit'])) { $myemail = 'my@email.com';//<-----Put Your email address here. $title = 'Quote'; $name = $_POST['name']; $company = $_POST['company']; $house = $_POST['house']; $street = $_POST['street']; $postcode = $_POST['postcode']; $daynum = $_POST['daynum']; $evenum = $_POST['evenum']; $email = $_POST['email']; $how = $_POST['how']; $information = $_POST['information']; foreach($_POST['product'] as $value) { $product_msg .= " - $value"; } $errors = array(); // set the errors array to empty, by default $fields = array(); // stores the field values $success_message = ""; // import the validation library require("validation.php"); $rules = array(); // stores the validation rules // standard form fields $rules[] = "required,name,Name is required."; $rules[] = "required,house,House number is required."; $rules[] = "required,street,Street is required."; $rules[] = "required,postcode,Post Code is required."; $rules[] = "required,daynum,Daytime Number is required."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } // no errors! redirect the user to the thankyou page (or whatever) else { // here you would either email the form contents to someone or store it in a database. // To redirect to a "thankyou" page, you'd just do this: // header("Location: thanks.php"); $to = $myemail; $email_subject = "Quote: $name"; $email_body = "You have received a new quote from $name. ". " Here are the details:\n \n Name: $name\n \n Company: $company\n \n House: $house\n \n Street: $street\n \n Postcode: $postcode\n \n Daytime Number: $daynum\n \n Evening Number: $evenum\n \n Email: $email\n \n Products: $product_msg\n \n Additional Information: $information\n \n How: $how"; $headers = "From: $title\n"; $headers .= "Reply-To: $email"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: thank-you.html'); } } ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="contact-form" class="cmxform"> <?php // if $errors is not empty, the form must have failed one or more validation // tests. Loop through each and display them on the page for the user if (!empty($errors)) { echo "<div class='phperror'>Please fix the following errors:\n<ul>"; foreach ($errors as $error) echo "<li>$error</li>\n"; echo "</ul></div>"; } if (!empty($message)) { echo "<div class='notify'>$success_message</div>"; } ?> <fieldset> <label for="name">Name:*</label> <label for="name" class="error">Please enter your name.</label> <input class="text" type="text" id="name" name="name" value="<?=$fields['name']?>"/> <label for="company">Company Name:</label> <input class="text" type="text" id="company" name="company"> <label for="house">House Number:*</label> <label for="house" class="error">Please enter your house number.</label> <input class="text" type="text" id="house" name="house" value="<?=$fields['house']?>"> <label for="street">Street Name:*</label> <label for="street" class="error">Please enter your street name.</label> <input class="text" type="text" id="street" name="street" value="<?=$fields['street']?>"> <label for="postcode">Post Code:*</label> <label for="postcode" class="error">Please enter your post code.</label> <input class="text" type="text" id="postcode" name="postcode" value="<?=$fields['postcode']?>"> <label for="daynum">Daytime Number:*</label> <label for="daynum" class="error">Please enter your number.</label> <input class="text" type="text" id="daynum" name="daynum" value="<?=$fields['daynum']?>"> <label for="evenum">Evening Number:</label> <input class="text" type="text" id="eve-num" name="evenum"> <label for="email">Email Address:</label> <input class="text" type="text" id="email" name="email"> </fieldset> <fieldset> <label>Cara Glass Product:</label> <label for="check[]" class="error">Please choose a product.</label> <div id="product"> <div class="radio-btn"> <label for="conservatory">Conservatory</label> <input type="checkbox" value="conservatory" id="conservatory" name="product[]" validate="required:true"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="windows">Windows</label> <input type="checkbox" value="windows" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="fascias">Fascias</label> <input type="checkbox" value="fascias" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="doors">Doors</label> <input type="checkbox" value="doors" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="rooftrim">Rooftrim</label> <input type="checkbox" value="rooftrim" name="product[]" /> </div><!--radio-btn--> </div><!--product--> <label for="information">Additional Information:</label> <textarea id="information" name="information"></textarea> </fieldset> <fieldset> <p>How Did You Hear About Us?</p> <div id="how"> <div class="radio-btn"> <label for="internet">Internet</label> <input type="radio" value="internet" id="internet" name="how"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="letter">Marketing Letter</label> <input type="radio" value="letter" id="letter" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="referral">Referral</label> <input type="radio" value="referral" id="referral" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="advertising">Advertising</label> <input type="radio" value="advertising" id="advertising" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="vans">Our Vans</label> <input type="radio" value="vans" id="vans" name="how" /> </div><!--radio-btn--> </div><!--how--> <p class="submit">Once we have received your details we will call you to arrange a convenient time</p> </fieldset> <input type="submit" name="submit" value="SUBMIT" /> </form> Im having a problem with my form mail on my websites. Now the problem I have only happens with sites that I upload to my hosting accounts with Host gator. The mail will only deliver to the domain email address it wont deliver to gmail or yahoo or any other email address. I tested the script on an old domain with an Irish hosting account and it works perfectly it delivers to gmail and yahoo and my domain email account. Ive been pulling my hair out talking to Hostgator staff all weekend they keep blaming gmail and yahoo and insist the problem is not on there end. Anyway I was wondering is there anything I can add to my PHP script to make sure it delivers to gmail and yahoo or is there anything wrong with my script as hostgator are saying. Maybe there is a security issue or something Im very new to php so i could be missing something simple.
Thanks for the Help
<?php /* Set e-mail recipient */ $myemail = "info@shaneswebdesign.com"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Enter your name"); $subject = check_input($_POST['subject'], "Write a subject"); $email = check_input($_POST['email']); $website = check_input($_POST['website']); $likeit = check_input($_POST['likeit']); $how_find = check_input($_POST['how']); $comments = check_input($_POST['comments'], "Write your comments"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email URL: $website Area of Interest? $how_find Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: http://www.shanesweb...m/thanks.php'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> Hi all, firstly thank you in advance to anyone who replies to this thread. I'll be honest I'm a newbie when I comes to PHP and really am a long way to mastering it. If someone could have a look at my code and tell me where I'm going wrong here then it would be a great help.
The problem here is, when I click on the submit button it sends me to the PHP script page and doesn't actually send a email to the address.
Please Help and again, thank you in advance.
Below is the HTML,
<section> I made a form using http://www.phpform.org/ but I can't for the life of me write some php that successfully collects all the info and emails it to me. Would love to get some help to stop me pulling m hair out over it - it can't be 'that' complicated? I'd just put the form here for now http://trackcover.com/test/ Hello All, I need some VERY DETAILED direction from anyone who can tell me how to complete this task. I set up my database "riptide" in Php MyAdmin for the following data to be submitted by user. Also a " form.php " form with the following fields. Salutation: Mr. Mrs. Ms. Miss. Dr. Prof. (radio buttons) input name="salutation" type="radio" value="Mr." checked First Name: (text input field) input name="first_Name" Last Name: (text input field) input name="last_Name" E-mail: (text input field) input name="email" Zip Code: (text input field) input name="zip_code" Would you like to receive our email newsletter? Yes No (radio buttons) input type="radio" name="newsletter" value="yes" id="newsletter_0" checked Okay here is my dilemma... I need to make web form that will do the following: (1) Connects to my database (2) INSERTS the form data filled out from my user into my MySQL database. (3) I need an email that will be sent to both me and the user who filled out the web form (4) A Thank you page "displaying" all the details the user filled out in the web form. (5) Plus all fields are required and need " validation " especially the e-mail address. I made a page called "process_form. php" that will handle all of this once the submit button is clicked. How do I make this happen? Thanks in advance James sir i need this contact form php code to make it work,
i make thi deign for my website but dont know what have to put in send.php
here i the code
<h4>Send a Message</h4> <div class="contact-form" method="post" action="send.php"> <form role="form"> <div class="form-group"> <label for="name">Name</label> <input type="text" name="name" placeholder="" id="name" class="form-control"> </div> <div class="form-group"> <label for="email">Email</label> <input type="text" name="email" placeholder="" id="email" class="form-control"> </div> <div class="form-group"> <label for="phone">Skype</label> <input type="text"name="subject" id="phone" class="form-control"> </div> <div class="form-group"> <label for="phone">Message</label> <textarea placeholder="" name="message" rows="5" class="form-control"></textarea> </div> <button class="btn btn-danger" type="submit">Submit</button> </form> Edited by soumikr, 22 December 2014 - 11:35 AM. Hello All, I've successfully figure out how to make a form that connects to My Database, INSERTS the END USERS INFO into my database, and THEN sends a email notification back to the ME that contains the the END USERS INFO. Is there a line of CODE in PHP to use that I can ALSO send the END USERS INFO from the form THEY FILLED OUT with all their details that was sent back to ME in the initial e-mail? Also how do I get the date and time to post in the in my e-mail received with from the END USERS containing the date and time of the form filled out. It shows up in my Database HOWEVER, not in my RECEIVED e-mail. Here is my code below: <pre> Code: [Select] <?php if (isset($_POST['submitted'])) { include('connect2myDB.php'); $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; $sqlinsert = "INSERT INTO travelers (salutation, first_name, last_name, email, zip_code, newsletter, registation_date) VALUES ('$salutation', '$first_name','$last_name','$email','$zip_code','$newsletter', NOW()))"; } ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'mrjap1jobs@gmail.com'; // GATHERING the FORM DATA VARIABLES $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; // THIS DATA DOES NOT SHOW UP IN MY RECEIVED E-MAIL HOWEVER, IT DOES SHOW UP IN MY DATABASE.... HOW DO I FIX THIS? $body = <<<EOD <br /><hr><br /> <strong>Salutation:</strong> $salutation <br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Zip Code:</strong> $zip_code <br /> <strong>Newsletter:</strong> $newsletter <br /> <strong>Registration Date:</strong> $registation_date <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> </pre> thanks mrjap1 MOD EDIT: code tags added. Hello All, I made an external "Thank you.html" page that I want to show immediately after the " Send Your Info" button on my "request_more_info.php " form is clicked. This MUST stay external always. I want this to be called in somehow by php. So is there some php code I can use to accomplish this? Also is there some php code I can use to validate my entire form and ESPECIALLY the e-mail address portion on my form? If so could you tell me who do i apply it to my "request_more_info.php " Salutation: (radio buttons) First Name: (input field) Last Name: (input field) Address: (input field) City: (input field) State: (select option) Zip: (input field) Country: (select option) Email: (input field) Our Newsletter: (radio buttons) thanks MrJAP1 I was able to edit this code from my word press theme.. I wanted to add a social club ID to as a text field, i was able to add the text field but i cannot seem to get the information from that field sent with the email I edited this contact form file on my word press to try and include a Social ID field, i was able to add the content to the form but i'm unable to get the information sent in the email, keeps giving me awkward results. help plz. <?php session_start(); /** * Template Name: Contact Form */ global $theme; get_header(); ?> <div id="main"> <?php $theme->hook('main_before'); ?> <div id="content"> <?php $theme->hook('content_before'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); /** * Find the post formatting for the pages in the post-page.php file */ get_template_part('post', 'page'); endwhile; else : get_template_part('post', 'noresults'); endif; ?> <div class="contact-form"> <?php if ($_POST['contact_form_submit'] ) { if(!$_POST['contact_form_name'] || !$_POST['contact_form_email'] || !$_POST['contact_form_subject'] || !$_POST['contact_form_socialid'] || !$_POST['contact_form_question'] || !$_POST['contact_form_message']) { ?><div class="error"><?php _e('Please fill in all required fields!','themater'); ?></div><?php } elseif(!is_email($_POST['contact_form_email'])) { ?><div class="error"><?php _e('Invalid email!','themater'); ?></div><?php } elseif(($_SESSION['contact_form_number_one'] + $_SESSION['contact_form_number_two']) != $_POST['contact_form_question']) { ?><div class="error"><?php _e('You entered the wrong solution..','themater'); ?></div><?php } else { wp_mail($theme->get_option('contact_form_email'), sprintf( '[%s] ' . esc_html($_POST['contact_form_subject']), get_bloginfo('name') ), esc_html($_POST['contact_form_message']),'From: "'. esc_html($_POST['contact_form_name']) .'" <' . esc_html($_POST['contact_form_email']) . '>'); unset($_POST); ?><div class="message"><?php _e('Thanks for contacting Devils First MC.','themater'); ?></div><?php } if ( isset($_SESSION['contact_form_number_one'] ) ) unset( $_SESSION['contact_form_number_one'] ); if ( isset($_SESSION['contact_form_number_two'] ) ) unset( $_SESSION['contact_form_number_two'] ); } if ( !isset($_SESSION['contact_form_number_one'] ) ) $_SESSION['contact_form_number_one'] = $contact_form_number_one = rand(1, 9); else $contact_form_number_one = $_SESSION['contact_form_number_one']; if ( !isset($_SESSION['contact_form_number_two'] ) ) $_SESSION['contact_form_number_two'] = $contact_form_number_two = rand(1, 9); else $contact_form_number_two = $_SESSION['contact_form_number_two']; ?> <form method="post" action=""> <input type="hidden" name="contact_form_submit" value="true" /> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_name']) { echo 'contact-form-required'; } ?>"><?php _e('Name','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_name" value="<?php if ( isset($_POST['contact_form_name']) ) { echo esc_attr($_POST['contact_form_name']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_socialid']) { echo 'contact-form-required'; } ?>"><?php _e('Social Club ID','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_socialid" value="<?php if ( isset($_POST['contact_form_socialid']) ) { echo esc_attr($_POST['contact_form_socialid']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_email']) { echo 'contact-form-required'; } ?>"><?php _e('Email','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_email" value="<?php if ( isset($_POST['contact_form_email']) ) { echo esc_attr($_POST['contact_form_email']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_question']) { echo 'contact-form-required'; } ?>"><?php echo $contact_form_number_one; ?> + <?php echo $contact_form_number_two; ?> = ?</div> <div class="contact-form-input"><input type="text" name="contact_form_question" value="" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_subject']) { echo 'contact-form-required'; } ?>"><?php _e('Subject','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_subject" value="<?php if ( isset($_POST['contact_form_subject']) ) { echo esc_attr($_POST['contact_form_subject']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_message']) { echo 'contact-form-required'; } ?>"><?php _e('Message','themater'); ?>:</div> <div class="contact-form-input"><textarea name="contact_form_message" ><?php if ( isset($_POST['contact_form_message']) ) { echo esc_textarea($_POST['contact_form_message']); } ?></textarea></div> <div class="contact-form-label alignleft"> </div> <div class="contact-form-input" style="text-align: center;"><input type="submit" value="<?php _e('Submit','themater'); ?>" /></div> </form> </div> <?php $theme->hook('content_after'); ?> </div><!-- #content --> <?php get_sidebars(); ?> <?php $theme->hook('main_after'); ?> </div><!-- #main --> <?php get_footer(); ?> hello All, Thank you EVERYONE for all of your help... it was much appreciated. I have created a form that does the following: (1) Connects to the database that created. (2) Inserts the users data into the database (3) Displays a thank you you page after a successful form submission (4) Send an e-mail to me with all the users details I NOW need to be able to send a Custom html page to the end users e-mail with all their data... a Confirmation e-mail for their reference. Is there some special PHP Code that can HANDLE such a task? If so please tell me how might be able to integrate this in my existing code. thanks mrjap1 Hello,
I need a contact form with fields:
Name:
Email:
Phone:
Message:
I have html contact form but when a visitor clicks on submit button then a pop up says thnq for contacting us and he need to be on the same page. the details has to get in mail to me.
Hi everyone, i was trying to create a little script for my blog but cant do that. What i want is this model with dropdown options: http://www.pasidedans.ro/inscrie-te-acum I want to replace my entire cod so i dont want to modify him.. Can you help me to create a contact form like this ? thanks ! |