PHP - Contact Us Form Not Working Properly
Unable to submit choosing a file. This feature should be optional, Please assist. Thank you. php code ========= <?php $page = 'contact'; require "header.php"; ?> <?php $statusMsg=''; if(isset($_FILES["file"]["name"])){ $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone']; $company = $_POST['company']; $option = $_POST['option']; $message = $_POST['message']; if(!empty($_POST['check_list'])) { $checks = array(); foreach($_POST['check_list'] as $check) { $checks[] = $check; } $check = implode('</br>•', $checks); } $fromemail = $email; $subject="MyGeo - Contact Us"; $email_message = '<h2>User Information</h2> <p><b>First Name:</b> '.$fname.'</p> <p><b>Last Name:</b> '.$lname.'</p> <p><b>Email:</b> '.$email.'</p> <p><b>Phone:</b> '.$phone.'</p> <p><b>Company:</b> '.$company.'</p> <p><b>Please choose a category :</b> '.$option.'</p> <p><b>Your message to MyGeo :</b> '.$message.'</p>'; $email_message.="Please find the attachment"; $semi_rand = md5(uniqid(time())); $headers = "From: ".$fromemail; $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; if($_FILES["file"]["name"]!= ""){ $strFilesName = $_FILES["file"]["name"]; $strContent = chunk_split(base64_encode(file_get_contents($_FILES["file"]["tmp_name"]))); $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "\n\n"; $email_message .= "--{$mime_boundary}\n" . "Content-Type: application/octet-stream;\n" . " name=\"{$strFilesName}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $strContent .= "\n\n" . "--{$mime_boundary}--\n"; } $toemail="jasmin.ambrose@mygeo.my"; if(mail($toemail, $subject, $email_message, $headers)){ $statusMsg= "Submission succesful, thank you for contacting MyGeo"; }else{ $statusMsg= "SUBMISSION FAILED, please submit again later, thank you"; } } ?> <!-- Display submission status --> <?php if(!empty($statusMsg)){ ?> <h1 class="container jumbotron text-uppercase text-center mx-auto" style=" font-size: 25px; color: green;"><?php echo $statusMsg; ?></h1> <?php } ?> <!-- Sectio-one --> <div class="col-md-12 square"> <h3 class="font-weight-bold"></h3> <h4 class="font-weight-bold">MyGeo Sdn. Bhd. (1367062-K)</h4> <h5>Level 2, Suite IIC Resource Centre, Technology Park Malaysia, Bukit Jalil, 57000 Kuala Lumpur, MALAYSIA</h5> <i class="fa fa-envelope-o" aria-hidden="true"></i> contactus@mygeo.my <i class="fa fa-phone" aria-hidden="true"></i> +6012 345 3263 </div> <div class="section-service py-5 my-1"> <div class="container"> <div class="row p-1"> <div class="col-xs-6"> <h1>HOW CAN WE HELP YOU</h1> </div> </div> <div class="row p-1"> <div class="col-md-12"> <p id="sep">Contact us below with new project requests, feedback and general questions</p> <form method="post" action="" enctype="multipart/form-data"> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="fname">First Name</label> <input name="fname" type="text" class="form-control" placeholder="First name" required> </div> <div class="form-group col-md-6"> <label class="font-weight-bold" for="lname">Last Name</label> <input name="lname" type="text" class="form-control" placeholder="Last name" > </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="inputEmail4">Email</label> <input name="email" type="email" class="form-control" id="inputEmail4" placeholder="Email" required> </div> <div class="form-group col-md-6"> <label class="font-weight-bold" for="Phone">Phone</label> <input name="phone" type="tel" class="form-control" id="phone" placeholder="Enter phone number" required> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="company">Company</label> <input name="company" type="text" class="form-control" placeholder="Company" > </div> </div> <div class="form-row"> <div class="form-group"> <label class="font-weight-bold" for="input" required>Please choose a category :</label> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="General Questions") echo "checked";?> value="General Questions" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> General Questions </label> </div> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="New Project Request") echo "checked";?> value="New Project Request" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> New Project Request </label> </div> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="Feedback") echo "checked";?> value="Feedback" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> Feedback </label> </div> </div> </div> <div class="form-group"> <label class="font-weight-bold" for="Textarea1">Your message to MyGeo</label> <textarea class="form-control" id="FormTextarea1" rows="3" name="message" required></textarea> <small id="emailHelp" class="form-text text-muted">0 of 4000 max charaacters</small> </div> <p></p> <p></p> <div class="form-group"> <label class="font-weight-bold" for="File1"></label> <input type="file" name="file" class="form-control-file" id="exampleFormControlFile1" required =""> </div> <button type="submit" class="btn btn-success" name="submit">Submit</button> </form> </div> </div> </div> </div> <?php require "footer.php"; ?>
footer.php ======= <!-- Footer --> <section id="footer"> <div class="container text-center"> <div class="row social"> <div class="col-xs-12 col-sm-12 col-md-12 mt-2 mt-sm-2"> <ul> <li class="list-inline-item"> <a href="#"><i class="fa fa-linkedin"></i></a></li> <li class="list-inline-item"> <a href="#"><i class="fa fa-twitter"></i></a></li> <li class="list-inline-item"> <a href="https://www.facebook.com/MyGeo-100967235334783"><i class="fa fa-facebook"></i></a></li> </ul> </div> </div> <div class="row"> <div class="col-xs-12 col-md-12 mt-2 mt-sm-2 text center text-white"> <p>© All Rights Reserved (2020)<a href="#"> MyGeo</a> Sdn. Bhd. (1367062-K)</p> <p>Level 2 Suite IIC Resource Centre Technology Park Malaysia, Bukit Jalil, 57000 Kuala Lumpur, MALAYSIA.</p> </div> </div> </div> </section> <script> function myFunction() { var input, filter, ul, li, a, i; input = document.getElementById("mySearch"); filter = input.value.toUpperCase(); ul = document.getElementById("myMenu"); li = ul.getElementsByTagName("li"); for (i = 0; i < li.length; i++) { a = li.getElementsByTagName("a")[0]; if (a.innerHTML.toUpperCase().indexOf(filter) > -1) { li.style.display = ""; } else { li.style.display = "none"; } } } </script> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> </body> </html>
header.php ======== <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>My GEO</title> <link rel="shortcut icon" type="image/png" href="images/mygeo logo2.png"> <link rel="stylesheet" href="./css/style.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"> </head> <body> <!-- Simple Responsive Navbar --> <nav class="navbar navbar-expand-xl text-success font-weight-600 pt-2"> <div class="container"> <a class="navbar-brand" href="index.php"><img style="width: 15vh;" src="images/mygeo logo2.png"></a> <button class="navbar-toggler navbar-light" data-toggle="collapse" data-target="#Nav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="Nav"> <ul class="navbar-nav" id="myMenu"> <li class="nav-item <?php if($page=='about'){echo 'active';}?>"> <a class="nav-link" href="about.php">ABOUT US</a> </li> <li class="nav-item <?php if($page=='services'){echo 'active';}?>"> <a class="nav-link" href="services.php">SERVICES</a> </li> <li class="nav-item <?php if($page=='projects'){echo 'active';}?>"> <a class="nav-link" href="projects.php">PROJECTS</a> </li> <li class="nav-item <?php if($page=='people'){echo 'active';}?>"> <a class="nav-link" href="people.php">MYGEO PEOPLE</a> </li> <li class="nav-item dropdown <?php if($page=='careers'){echo 'active';}?>"> <a class="nav-link dropdown-toggle " data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CAREERS</a> <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <a class="dropdown-item" href="career-a.php">TELL US ABOUT YOURSELF</a> <a class="dropdown-item" href="career-b.php">JOB OPENINGS</a> </div> </li> <li class="nav-item <?php if($page=='blog'){echo 'active';}?>"> <a class="nav-link" href="https://mygeomalaysia.wordpress.com/">BLOG</a> </li> <li class="nav-item <?php if($page=='webmail'){echo 'active';}?>"> <a class="nav-link" target="_blank" href="https://mygeo.my/webmail">WEBMAIL</a> </li> <li class="nav-item <?php if($page=='contact'){echo 'active';}?>"> <a class="nav-link" href="contact-a.php">CONTACT US</a> </li> </ul> </div> </div> </nav>
Edited April 19 by requinix please use the Code <> button when posting code Similar Tutorials<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact Us</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <!-- Template 2043 Pinky Flow http://www.tooplate.com/view/2043-pinky-flow --> <link href="css/tooplate_style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/ddsmoothmenu.js"> /*********************************************** * Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ </script> <script type="text/javascript"> ddsmoothmenu.init({ mainmenuid: "tooplate_menu", //menu DIV id orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" classname: 'ddsmoothmenu', //class added to menu's outer DIV //customtheme: ["#1c5a80", "#18374a"], contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] }) </script> <link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" /> <!-- Arquivos utilizados pelo jQuery lightBox plugin --> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script> <link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" /> <!-- / fim dos arquivos utilizados pelo jQuery lightBox plugin --> <!-- Ativando o jQuery lightBox plugin --> <script type="text/javascript"> $(function() { $('#map a').lightBox(); }); </script> </head> <body> <div id="tooplate_wrapper"> <div id="tooplate_header"> <div id="site_title"><h1><a href="index.html">Rubi Noodle Studios</a></h1></div> <div id="tooplate_menu" class="ddsmoothmenu"> <ul> <li><a href="index.html" class="selected"><span></span>Home</a></li> <li><a href="gallery.html"><span></span>Galleries</a> <ul> <li><a href="families.html">Families</a></li> <li><a href="children.html">Children</a></li> <li><a href="graduates.html">Graduates</a></li> <li><a href="engagement.html">Engagement</a></li> <li><a href="weddings.html">Weddings</a></li> <li><a href="maternity.html">Maternity</a></li> </ul> </li> <li><a href="information.html"><span></span>Information</a> <ul> <li><a href="announcements.html">Graduation Announcements</a></li> <li><a href="pricing.html">Pricing</a></li> <li><a href="hints.html">Helpful Hints</a></li> </ul> </li> <li><a href="client.html"><span></span>Client Viewing</a></li> <li><a href="contact.html" class="selected"><span></span>Contact</a></li> <li><a href="http://www.facebook.com"> <img src="images/facebook.png" alt="Facebook" style="width:33px;height:32px;border:0" /> </a></li> </ul> <br style="clear: left" /> </div> <!-- end of tooplate_menu --> <div id="tooplate_main"> <div id="tooplate_content"> <h2>Contact Information</h2> <p><em>Have a question about a session or want to set up a session? Please feel free to contact me.</em></p> <div class="h30"></div> <div class="col_w420 float_l"> <div id="contact_form"> <h3>Quick Contact Form</h3> <?php if (isset($_POST['submit'])) { if ($_POST['author'] != "") { $_POST['author'] = filter_var($_POST['author'], FILTER_SANITIZE_STRING); if ($_POST['author'] == "") { $errors .= 'Please enter a valid name.<br/><br/>'; } } else { $errors .= 'Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>"; } } else { $errors .= 'Please enter your email address.<br/>'; } if ($_POST['subject'] != "") { $email = filter_var($_POST['subject'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= 'Please enter a subject.<br/></br>'; } } else { $errors .= 'Please enter your subject.<br/>'; } if ($_POST['text'] != "") { $_POST['text'] = filter_var($_POST['text'], FILTER_SANITIZE_STRING); if ($_POST['text'] == "") { $errors .= 'Please enter a message to send.<br/>'; } } else { $errors .= 'Please enter a message to send.<br/>'; } if (!$errors) { $author=$_POST['author']; $email=$_POST['email']; $subject = 'Vistor:Email'; $text=$_POST['text']; mail("myemail@yahoo.com","$subject", $text,"From: $author <$email>"); header("Location:contact.php?thankyou"); exit(); } else { echo '<div style="color: red">' . $errors . '<br/></div>'; } } ?> <?php //Then outside the processing script add if (isset($_GET['thankyou'])){ echo "Thank you for your email!<br/><br/>"; } ?> <form method="post" name="form1" action="contact.php" /> <label for="author">* Name:</label> <input type="text" id="author" name="author" class="required input_field" value="<?php echo $_POST['author']; ?>"/> <div class="cleaner h10"></div> <label for="email">* Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" value="<?php echo $_POST['email']; ?>" /> <div class="cleaner h10"></div> <label for="subject">* Subject:</label> <input type="text" class="validate-subject required input_field" name="subject" id="subject" value="<?php echo $_POST['subject']; ?>" /> <div class="cleaner h10"></div> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required" value="<?php echo $_POST['text']; ?>" ></textarea> <div class="cleaner h10"> </div> <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" /> <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" /> </form> </div> </div> <div class="col_w420 float_r"> <h3>Location</h3> <div id="map"> <a href="images/map_big.png" title="Our Location"> <img width="300" height="150" src="images/map_thumb.png" alt="Location" class="image_wrapper" /> </a> </div> <div class="cleaner h30"></div> <h3>Mailing Address</h3> <h6>Address</h6> Address <br /> <br /> <br /><br /> <strong>Phone:</strong> 020-054-1520<br /> <strong>Email:</strong> <a href="mailto:info@company.com">info@company.com</a> </div> <div class="cleaner"></div> </div> <div class="cleaner"></div> </div> <!-- end of tooplate_main --> <div id="tooplate_footer"> Copyright © 2014 <a href="index.html">Rubi Noodle Studios</a> | Design: <a href="http://www.tooplate.com">tooplate</a> <div class="cleaner"></div> </div> </div> <!-- end of forever header --> </div> <!-- end of forever wrapper --> </body> </html>When I run my contact form on my webserver and fill it out completely and submit it, I get my error message saying "Please enter a subject." when I have a subject. Hi I am brand new to PHP Freaks and really hope someone can help me out with my php problem. I have a contact form that I am using and all the php and form info is in one file. The contact form worked before but it wasn't correct because one of the names was wrong on the form. Here is the php I have put just below the opening body tag: <?php $name = $_POST["name"]; $email = $_POST["email"]; $subject = $_POST["subject"]; $comment = $_POST["comment"]; $submit = $_POST["submit"]; if(isset($submit)){ $sendTo = "myemail@mydomain.com"; $message = "<h3>To You:</h3> $comment<br /> <br /> From: $name ($email)"; $headers = "From: $name <$email> \r\n"; $headers .= "X-Mailer:PHP/\r\n"; $headers .= "MIME-Version:1.0\r\n"; $headers .= "Content-type:text/html; charset=iso-8859-1\r\n"; $sent = mail($sendTo, $subject, $message, $headers); } ?> and here is the form: <form action="" method="post"> <table> <tr> <td>Name: </td> <td><input type="text" name="name" class="field"/></td> </tr> <tr> <td>Email: </td> <td><input type="text" name="email" class="field" /></td> </tr> <tr> <td>Subject: </td> <td><input type="text" name="subject" class="field"/></td> </tr> <tr> <td>Comment: </td> <td><textarea name="comment" cols="30" rows="8" > </textarea></td> </tr> <tr> <td><input type="submit" name="submit" value="Send" /></td> </tr> </table> </form> <?php if ($sent){ echo "Thank you for your message!"; } ?> now when I had it working I had accidentally had the subject name set to "email" but when I simply change it to "subject" as it should be it won't work anymore. I would love to just let it work the wrong way but this won't work because when I receive the email it displays the subject instead of the persons email and I need to see the email to get back to them. I really hope someone can help me with this! Thanks, Curtis Hi Guys, I am sure you will laugh at my coding attempt, but i need your help. I have set up a contact form and a PHP process to send the email. Everything appears to be working except the sending part. All fields validate as they should, the form forward to a thank you page as it should. But no emails are received either at my domain end or from the sender i am testing with. Here is my form code: Code: [Select] <form id="form1" name="form1" method="post" action="emailform.php" onsubmit="window.setTimeout(function(){window.location='/thankyou.html'},20); return true;"> <p><span id="sprytextfield1"> <label for="name">Name: </label> <input name="name" type="text" id="name" tabindex="10" /> <span class="textfieldRequiredMsg">Your name is required.</span><span class="textfieldMaxCharsMsg">No more than 50 characters in your Name.</span><span class="textfieldMinCharsMsg">Your Name must be atleast 4 characters long.</span></span></p> <p><span id="sprytextfield2"> <label for="email">Email: </label> <input type="text" name="email" id="email" tabindex="20" /> <span class="textfieldRequiredMsg">An Email Address is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p><span id="spryselect1"> <label for="state">State</label> <select name="state" id="state" tabindex="30"> <option>ACT</option> <option>NSW</option> <option>Queensland</option> <option>Victoria</option> <option>Tas</option> <option>SA</option> <option>WA</option> <option>NT</option> </select> <span class="selectInvalidMsg">Please select a valid State.</span></span></p> <p>What styles are you interested in doing? <label for="styles"></label> <select name="styles" id="styles" tabindex="40"> <option>Portraits</option> <option>Fashion</option> <option>Swimwear</option> <option>Lingerie</option> <option>Art Nude</option> <option>All Styles Possible</option> <option>Just Curious for Now</option> </select> </p> <p>Please leave any Message or Comments Below:</p> <p><span id="sprytextarea1"> <label for="comments"></label> <textarea name="comments" id="comments" cols="45" rows="5" tabindex="50"></textarea> <span class="textareaRequiredMsg">Please enter your comments here.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Send Form" tabindex="50" /> </p> </form> Here is the PHP Code: <?php /* Subject and variables */ $emailSubject = 'New Email Enquiry'; $webMaster = 'enquiry@davids-photography.com'; /* Gathering data variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $stateField = $_POST['state']; $stylesField = $_POST['styles']; $commentsField = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> State: $state <br> Style: $style <br> Comment: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); ?> Any help you can offer would be greatly appreciated. I am not looking for anything over the top, just something simple that works. Thanks David Hi, Just wondered if anyone can help? A contact form which has previously worked has stopped working, I presume because the PHP has been upgraded to version 5.6. If anyone is able to advise on how I need to tweak it, it would be massively appreciated! Code below: Thanks, Sarah <? // edit these lines $your_name="Company Name"; $your_email="sarah@companyname.co.uk"; $your_web_site_name="companyname.co.uk"; ?> <?php //If the form is submitted if(isset($_POST['name'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) === '') { $commentError = 'Please enter your message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = $your_email; $subject = 'Contact Form Submission from '.$name; $body = "Name: $name \n\nEmail: $email \n\nPhone: ".trim($_POST['phone'])." \n\nComments: $comments"; $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?php if(isset($emailSent) == true) { ?> <div class="ok"> <h1>Thanks, <?php echo $name;?></h1> <p>Your email was successfully sent. We will be in touch soon.</p> </div> <?php } ?> <?php if(isset($hasError) ) { ?> <div class="error2">There was an error submitting the form.</div> <?php } ?> Okay, the following php form is "somewhat" working. .I am not receiving all of the variables to my inbox.
This is the current form that i'm working on.
http://www.rodriguez...cr/schedule.php
The following fields are the ones are not passing through.
The Drop Down Menu: am, pm, the all day
Video
Case Option:
Additional Requests:
Firm Physical Address:
Fax No:
Here is the code
<?php function displayRequired($fieldName) { echo " \".$fieldName\"is required.<br />n"; } function validateInput($data, $fieldName){ global $errorCount; if (empty($data)){ displayRequired($fieldName); ++$errorCount; $retval = ""; } else { $retval = trim($data); $retval = stripslashes($retval); } return ($retval); } $Deposition = validateInput(safe($_POST['deposition']), "Deposition"); $Time = validateInput(safe($_POST['time']), "Time"); $Delivery = validateInput(safe($_POST['delivery']), "Delivery"); $Witness = validateInput(safe($_POST['witness']), "Witness"); $Location = validateInput(safe($_POST['location']), "Location"); $Attorney = validateInput(safe($_POST['attorney']), "Attorney"); $Name = validateInput(safe($_POST['name']), "First Name"); $Firm = validateInput(safe($_POST['firm']), "Firm Name"); $Phone = validateInput(safe($_POST['phone']), "Phone"); $Email = validateInput(safe($_POST['email']), "Email"); if ($errorCount>0){ echo "Please re-enter the information below.<br />\n"; redisplayForm($Deposition, $Time , $Ampm, $Timeday, $Delivery, $Video, $Co1, $Co2, $Witness, $Location, $Additional, $Attorney, $Name, $Firm, $Address, $Phone, $Fax, $Email); } else { $To = "service@rodriguezstudios.com"; $Subject = "The test"; $From = "Schedule a Deposition - Professional Court Reporters"; $Message .= "Deposition Date: " . $Deposition . "\n"; $Message .= "Time: " . $Time . $Ampm. $Timeday . "\n\n"; $Message .= "Transcript Delivery: " . $Delivery . "\n\n\n"; $Message .= "Video: " . $Video . "\n\n\n\n"; $Message .= "Case Option: " . $Co1. "vs: " . $Co2 . "\n\n\n\n\n"; $Message .= "Witness: " . $Witness . "\n\n\n\n\n\n"; $Message .= "Location: " . $Location . "\n\n\n\n\n\n\n"; $Message .= "Additional Requests: " . $Additional. "\n\n\n\n\n\n\n\n"; $Message .= "Attorney Name: " . $Attorney . "\n\n\n\n\n\n\n\n\n"; $Message .= "Your Name: " . $Name . "\n\n\n\n\n\n\n\n\n\n"; $Message .= "Firm Name: " . $Firm. "\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Firm Physical Address: " . $Address . "\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Phone No: " . $Phone . "\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Fax No: " . $Fax. "\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Email: " . $Email . "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Headers = "From: ". $From . "<" . $To. ">\r\n"; $Headers .= "Reply-To: " . $Email . "\r\n"; $Headers .= "Return-path: ". $Email; $result = mail($To, $Subject, $Message, $Headers); if ($result) $resultMsg = "You message was sucessfully sent."; else $resultMsg = "There was a problem sending your message."; /*insert anti spam fragement here */ ?> <p style="line-height:200%; text-align:center; font-family:Verdana, Geneva, sans-serif; color:#000000">Your deposition has been scheduled<?php if(!empty($fieldName)) { echo " , {$fieldName}. {$resultMsg}"; } echo "</p>"; } ?> <?php function redisplayForm($Deposition, $Time , $Ampm, $Timeday, $Delivery, $Video, $Co1, $Co2, $Witness, $Location, $Additional, $Attorney, $Name, $Firm, $Address, $Phone, $Fax, $Email){ ?> <form action="" method="POST"> <fieldset class="first"> <fieldset class="first"> <p> <label class="labelone"for="deposition">*Deposition Date:</label> <input type="text" id="datepicker" name="deposition" value="<?php echo $Deposition; ?>" /> </p> <p> <label for="*Time:" name="time">*Time: </label> <input type="text" name="time" value="<?php echo $Time; ?>"> <select name="ampm" id="Ampm"> <option value="am">A.M.</option> <option value="pm">P.M.</option> </select> <select name="timeday" id="Timeday"> <option value="all">All Day</option> <option value="half">Half Day</option> <option value="hours">1-2 hrs</option> </select> </p> <p> <label for="*Transcript Delivery:" name="transcript"/> *Transcript Delivery:</label> <select> <option value="regular">Regular Delivery (10 day)</option> <option value="same">Same Day</option> <option value="1day">1 Day</option> <option value="2day">2 Day</option> <option value="3day">3 Day</option> <option value="4day">4 Day</option> <option value="5day">5 Day</option> </select> </p> <p> <label for="*Video" name="video">*Video:</label> <select name="video" id="video"> <option value="yes">Yes</option> <option value="no">No</option> </select> </label> </p> <p> <label for ="caseoption">Case Option:</label> <input type="text" name="co1" value="<?php echo $Co1; ?>"/> vs. <input type="text" name="co2" value="<?php echo $Co2; ?>" /> </p> <p> <label for ="witness">*Witness:</label> <input type="text" name="witness" value="<?php echo $Witness; ?>" /> </p> </fieldset> <fieldset> <legend>LOCATION OF DEPOSITION, TELEPHONE NUMBER, AND NAME OF CONTACT PERSON:</legend> <p> <label for="location">*Location:</label> <textarea name="location" id="Location" value="<?php echo $Location; ?>"></textarea> </p> <p> <label for="additional">Addtional Requests (i.e. Realtime):</label> <input type="text" name="additional" value="<?php echo $Additional; ?>" /> </p> <p> <label for ="attorney">*Attorney Name:</label> <input type="text" name="attorney" value="<?php echo $Attorney; ?>" /> <p> <label for ="name">*Your Name:</label> <input type="text" name="name" value="<?php echo $Name; ?>" /> </p> <label for ="firm">*Firm Name:</label> <input type="text" name="firm" value="<?php echo $Firm; ?>" /> </p> <p> <label for ="firmaddress">Firm's Physical Address:</label> <input type="text" name="address" value="<?php echo $Address; ?>" /> </p> <p> <label for ="phone">*Phone No:</label> <input type="text" name="phone" value="<?php echo $Phone; ?>"/> </p> <p> <label for ="fax">Fax No:</label> <input type="text" name="fax" value="<?php echo $Fax; ?>"/> </p> <p> <label for ="email">*Email:</label> <input type="text" name="email" value="<?php echo $Email; ?>" /> </p> </fieldset> <fieldset> <input class="btn" name="submit" type="submit" value="Send Email"/> <input class="btn" name="reset" type="reset" value="Clear Form" /> </fieldset> </form> <?php } ?> <?php function safe($string) { $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; return preg_replace($pattern, '', $string); } ?>The extra pair of eyes would be greatly appreciated! I really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div> Edited February 20, 2020 by mike3075 Hey guys, New to the forum and a newer user of PHP / MySQL. I am having trouble with some code I've written up. I don't seem to get any errors when running it, but it's not updating my database the way that it should. hopefully a simple fix. I am thinking that it must be on the MySQL side of things. Couple of things to start. My html form is comprised completely of drop down list inputs. I'm the only user so I thought this would be the easiest approach. Because of that I've made my PHP as follows: Code: [Select] <?php $season = $_POST['season']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $time = $_POST['time']; $event = $_POST['event']; $game = $_POST['game']; $buyin = $_POST['buyin']; $connect = mysql_connect('localhost','root','') or die('can not connect'); if ($connect) { echo "connected to database"; } $db = mysql_select_db('dpl') or die('can not find database'); if ($db) { echo "DPL Selected"; } $query = sprintf("INSERT INTO events (season , month , day , year , time , event , game , buyin) VALUES ('%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s')", $season , $month , $day , $year , $time , $event , $game , $buyin ); if ($query) { echo "Your event has been added"; } ?> My connection is working, my database is selected and I'm even now getting confirmation that my query is working, but when i go to check my database there are no entries in it? any thoughts? I've tried the drop down variables as both VARCHAR and TEXT inputs in MySQL, but I can't seem to get it to work. Any help is greatly appreciated. I'm trying to get the form not to send unless the user includes there email address AND include some text in the "enquiry" box. At the moment the error message "Required fields are empty" appears when the submit button is pressed Code: [Select] <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } // The form was submitted // if (isset($_POST['button'])) { if (isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){ $fun = array( 'virusandmalwareremoval', 'fullservice', 'quickfix', 'upgrade', 'xbox360drivereplacement', 'xbox360laserreplacement', 'xbox360rrodrepair', 'ps3drivereplacement', 'ps3laserreplacement', 'ps3ylodrepair', 'databackup', 'websites', 'datarecovery', 'networkinstallation', 'mobilephoneissues', 'emailconfiguration' ); foreach ($fun as $value) { ${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : ''); } $name = $_REQUEST['name']; $email = $_REQUEST['email']; $enquiry = $_REQUEST['enquiry']; if (ereg("[\r\n]", $name) || ereg("[\r\n]", $email)) { header( "Location: http://www.parkersmedia.com/byrne" ); } $mailcontent = "Name: ".$name; $mailcontent.= "\n\nEmail: ".$email; $mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration; $mailcontent.= "\n\nEnquiry: " . $enquiry; if (mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services","$mailcontent", "From: $name <$email>" )) { header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" ); } else { echo 'Mail not sent'; } } else { echo 'Required fields are empty'; } } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Byrne Computing Services</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="inc/jquery.js"></script> <script type="text/javascript" src="inc/easySlider.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#slider").easySlider(); }); </script> </head> <body> <div id="wrapper"> <?php include ('inc_header.html'); ?> <?php include ('inc_scrollingimages.html'); ?> <div id="boxesholder"> <?php include ('inc_specials.html'); ?> <div id="main"> <div id="mainheader"> Contact Us</div> <div id="maincontent2"> <h2>Fill in the form below and we will contact you shortly.</h2> <p><img src="images/binarycode.jpg" alt="Binary Code" width="167" height="600" class="images" /><form id="form1" name="form1" method="post" action="contact-us.php"> <strong>Name: </strong><br /> <input name="name" type="text" class="formsingle" id="name" /> <br /> <br /> <strong>Email:</strong><br /> <input name="email" type="text" class="formsingle" id="emailaddress" /> <br /> <br /> <strong>Interested in:</strong><br /> <table border="0" cellspacing="0" cellpadding="0" class="table"> <tr> <td class="interestedin"><strong>Computer Repair</strong></td> <td class="interestedin"><strong>Console Repair</strong></td> <td class="interestedin"><strong>Other Services</strong></td> </tr> <tr> <td class="interestedin"> <input name="virusandmalwareremoval" type="checkbox" class="formcheckbox" id="virusandmalwareremoval" value="virusandmalwareremoval" /> <label for="virusandmalwareremoval">Virus and Malware Removal</label> </td> <td class="interestedin"> <input name="xbox360drivereplacement" type="checkbox" class="formcheckbox" id="xbox360drivereplacement" value="xbox360drivereplacement" /> <label for="ps3drivereplacement">Xbox 360 Drive Replacement</label> </td> <td class="interestedin"> <input name="databackup" type="checkbox" class="formcheckbox" id="databackup" value="databackup" /> <label for="databackup">Data Backup</label> </td> </tr> <tr> <td class="interestedin"> <input name="fullservice" type="checkbox" class="formcheckbox" id="fullservice" value="fullservice" /> <label for="fullservice">Full Service</label> </td> <td class="interestedin"> <input name="xbox360laserreplacement" type="checkbox" class="formcheckbox" id="xbox360laserreplacement" value="xbox360laserreplacement" /> <label for="ps3laserreplacement">Xbox 360 Laser Replacement</label> </td> <td class="interestedin"> <input name="websites" type="checkbox" class="formcheckbox" id="websites" value="websites" /> <label for="websites">Web Design</label> </td> </tr> <tr> <td class="interestedin"> <input name="quickfix" type="checkbox" class="formcheckbox" id="quickfix" value="quickfix" /> <label for="quickfix">Quick Fix</label> </td> <td class="interestedin"> <input name="xbox360rrodrepair" type="checkbox" class="formcheckbox" id="xbox360rrodrepair" value="xbox360rrodrepair" /> <label for="ps3ylodrepair">Xbox 360 RROD Repair</label> </td> <td class="interestedin"> <input name="datarecovery" type="checkbox" class="formcheckbox" id="datarecovery" value="datarecovery" /> <label for="datarecovery">Data Recovery</label> </td> </tr> <tr> <td class="interestedin"> <input name="upgrades" type="checkbox" class="formcheckbox" id="upgrades" value="upgrades" /> <label for="upgrades">Upgrades</label> </td> <td class="interestedin"><input name="ps3drivereplacement" type="checkbox" class="formcheckbox" id="ps3drivereplacement" value="ps3drivereplacement" /> <label for="ps3drivereplacement">PS3 Drive Replacement</label></td> <td class="interestedin"> <input name="networkinstallation" type="checkbox" class="formcheckbox" id="networkinstallation" value="networkinstallation" /> <label for="networkinstallation">Network Installation</label> </td> </tr> <tr> <td> </td> <td class="interestedin"><input name="ps3laserreplacement" type="checkbox" class="formcheckbox" id="ps3laserreplacement" value="ps3laserreplacement" /> PS3 <label for="ps3laserreplacement"> Laser Replacement</label></td> <td class="interestedin"> <input name="mobilephoneissues" type="checkbox" class="formcheckbox" id="mobilephoneissues" value="mobilephoneissues" /> <label for="mobilephoneissues">Mobile Phone Issues</label> </td> </tr> <tr> <td> </td> <td class="interestedin"><input name="ps3ylodrepair" type="checkbox" class="formcheckbox" id="ps3ylodrepair" value="ps3ylodrepair" /> <label for="ps3ylodrepair">PS3 YLOD Repair</label></td> <td class="interestedin"> <input name="emailconfiguration" type="checkbox" class="formcheckbox" id="emailconfiguration" value="emailconfiguration" /> <label for="emailconfiguration">Email Configuration</label></td> </tr> </table> <br /> <strong>Enquiry: </strong><br /> <textarea name="enquiry" class="formmulti" id="enquiry"></textarea> <br /> <br /> <input type="submit" name="button" id="button" value="Submit" /> </form> </p> <p><br /> </p> </div> </div> </div> <?php include ('inc_offers.html'); ?> <?php include ('inc_footer.html'); ?> </body> </html> 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 there, I have created an email script and i want it to email a different email depending on the subject chosen by raido boxes however the if's aren't doing what they should, If i select say recruitement it choses the last option and has the wrong subject here is my code: <html> <head> </head> <body> <form action="contact.php" method="post"> <fieldset> <legend>Contact Us</legend> Your Email:*<br> <input type="text" name="email"><br> Subject:*<br> Recruitment Enquiry:<input type="radio" name="subject" value="Recruitment"> Absense Notification:<input type="radio" name="subject" value="Absense"> General Enquiry<input type="radio" name="subject" value="Enquiry"> <br> Message:*<br> <textarea name="message" cols="50" rows="5"></textarea><br> <input type="submit" value="Send Email"> </form> Required fields are marked with a *<br><br> <?php if(isset($_POST)) { $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; //checcking that all relevent information is entered and correct if(!$email || !$message) { $errmessage ="Please fill in all required fields."; } if($subject="Recruitment") { $to="email1"; } if($subject="Notification") { $to="email2k"; } if($subject="Enquiry") { $to="email3"; } //Sending the email if nothing is wrong if(!$errmessage) { header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message.""); }else{ echo $errmessage; } } ?> </body> </html> If anyone can help it would be greatly appriciated Thanks, blink359 Okay, so I am trying to make a play.php file connected to my database, this database got a table named "webclientcreate". When I go to play.php?id=1, it is showing the proper one (the 1st row wich got id 1 in it), however if I after that go to something random like play.php?fsfasd the ID 1s page still pops up.. I can also go to play.php?id=2 and still get the id 1's data. I want to make it that every row got its own information (well it does, but the php file doesnt seem to recieve it correctly). PHP version: 5.2.17 MySQL version: 5.1 Heres a picture of my table rows: I've censored the MySQL connection information, I know it is working properly. Code: [Select] <?php $connect = mysql_connect("mysql12.000webhost.com","****","******") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $extract = mysql_query("SELECT * FROM webclientcreate"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $server = $row['name']; $ip = $row['ip']; $port = $row['port']; $background = $row['background']; } if (isset($ip)&&isset($port)&&!empty($ip)&&!empty($port)) { if (! $sock = @fsockopen($ip, $port, $num, $error, 1)) echo ""; else{ echo "<img src='fs/newyear/online.png'/>$ip on port $port is currently<B><FONT COLOR=lime> Online</b></FONT>"; fclose($sock); } } ?> <title>Playing <?php echo $server; ?> - ID <?php echo $id; ?> </title> <center> <body bgcolor="#000000"> <applet name=client width=765 height=503 archive='<?php echo $jars; ?>' code='client.class'> <PARAM name='java_arguments' value='-Xmx700m'> <PARAM name='server_name' value='<?php echo $server; ?>'> <PARAM name='detail' value='low'> <PARAM name='ip' value='<?php echo $ip; ?>'> <PARAM name='port' value='<?php echo $port; ?>'> <PARAM name='background_image' value='<?php echo $background; ?>'> <PARAM name='headicons' value=''> </applet> </center> This is the first time Im trying to use REGEXP, but cant get it working. It gives no error, just nothing..Anyone got idea why, please? Thanks <?php include ('connectToDatabase.php'); $getSearch = $_REQUEST['getSearch']; $keywordSearchQuery = "SELECT shoeName, shoeSize, colour, price, gender, description WHERE shoeName REGEXP '.*($getSearch).*' || shoeSize REGEXP '.*($getSearch).*' || colour REGEXP '.*($getSearch).*' || price REGEXP '.*($getSearch).*' || gender REGEXP '.*($getSearch).*' || description REGEXP '.*($getSearch).*" ; $keywordSearchQueryResult = mysql_query($keywordSearchQuery); echo "$keywordSearchQueryResult"; ?> hello.. In this script. if part is working properly. but elseif part not working i expect. it display only 1 category and its subjects. Anybody can tell me what the mistake that I have did... Here is my script Code: [Select] } elseif ( isset($_POST['category']) && ( sizeof( $_POST['category']) == 2 || sizeof( $_POST['category']) == 3 )) { $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { foreach( $category as $value ) { if ( $value == $row['category_id']) { echo '<input type="radio" name="category[]" value="' . $row['category_id'] . '" class="radio" />'; echo '<label for="" class="radio"> ' . $row['category_name'] . ' <strong>: Mark this category as my "Main Category"</strong></label><br />'; $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$row['category_id']}"; $r = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($info = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $info['subject_id'] . '" /> ' . $info['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } Why is my code below not working properly? I've tried it with == instead of = and it still doesn't work. I've verified using echo statements that $row['name'] = $_POST['name'] and $row['password'] = $_POST['password'] for one of the people in my database, but it still gives the message "Login or password wrong!" Thanks a lot for any help, here is the relevant part of my code (counterInt is defined to be 0 further up): while($row = mysql_fetch_array( $result )) { if($row['name'] = $_POST['name'] & $row['password'] = $_POST['password']) { $counterInt++; session_start(); $_SESSION['name']=$row['name']; } } if(counterInt == 1) { header( 'Location: http://simbazeviangame.99k.org/game.php' ); } if(counterInt == 0) { echo "Login or password wrong!"; } Here's the code with the function that won't work! Code: [Select] $itemsRaw = explode(" ", $player['inventory']); foreach ($itemsRaw as $inv){ $contents = explode("-", $inv); if(strlen($contents[0]) > 0 && strlen($contents[1]) > 0 && $contents[1] > 0) echo getItemName($contents[0]) . " (" . number_format($contents[1]) . ")<br />"; } Here's my function: Code: [Select] function getItemName($id_raw){ $id = $id_raw - 1; $q = $db->query("SELECT * FROM items WHERE id = $id") or die(mysql_error()); $f = $db->fetch_assoc($q); return $f['name']; } It stops the page when it gets to that point and won't load anything else and the function doesn't even work with it :/ What's wrong with it? If anything.. I'm trying to do a string match of a "what is my browser" return
I counted the indexes, there are 30
I have this code, I tested four different browsers, Internet Explorer, Chrome, Chromium, Firefox
Only chromium works, why? I counted the indexes for both Firefox and Chromium output, they are identical unless I miscounted
I don't have internet explorer or chrome, I had a friend test pull up the link that has this code
<?php $browsee = get_browser(null,true); $array = (array_slice($browsee,5,-24)); if(in_array("Firefox",$array)){ echo "your browser is firefox"; }else if(in_array("Chromium",$array)){ echo "your browser is chromium"; }else if(in_array("Chrome",$array)){ echo "your browser is chrome"; }else if(in_array("Explorer",$array)){ echo "your browser is Internet Explorer"; }else{ echo "your browser was not detected"; } echo '<br>'; echo '<br>'; print_r($browsee); ?>These are screenshots of the two browsers I use (I'm a Linux user) chromium.png 125.92KB 0 downloads firefox.png 137.44KB 0 downloads Hi everyone, my contact us form and script isn't working how it should. On send the data is not sent to the db, a () is the ONLY thing shown in the browser too, can somebody help make this work? Heres the form: Code: [Select] <form method="get" action="contact-send.php"> Name:<br /> <input type="text" name="name" id="name" size="30" /><br /> Email:<br /> <input type="email" name="email" id="email" size="30" /><br /> Your Question:<br /> <textarea name="question" id="question" rows="10" cols="50"></textarea><br /> <input type="submit" name="submit" value="send" /> </form And the script to process: Code: [Select] <?PHP session_start(); include ('php only scripts/db.php'); if ($db_found) { $SQL = "INSERT INTO 'contact_us' (name, email, question) VALUES ('" .$name. "', '" .$email. "', '" .$question. "')"; $result = mysql_query($query) or die(mysql_error()); header( 'Location: http://www.removalspace.com/contactconf.php' ); } ?> Iv'e messed with it and had database NOT found before but since then, messed some more and before i go in circles i need some help :| Thanks in advance for any help! Hi, I'm having problems with a PHP mail handler and everything seems to be working fine except I get slashes in the message body from the form. If my input is "Please don't delete this" I get "Please don/'t delete this" in the message body, however it is striping the other tags. I'm not sure what is wrong and was hoping for a bit of help to figure this out. Here is the code: Code: [Select] <?php $owner_email = $_POST["owner_email"]; $headers = 'From:' . $_POST["email"]; $subject = 'Website contact inquiry from ' . $_POST["name"]; $messageBody = ""; $messageBody .= '<p>------------------ Contact Details ------------------' . '</p>' . "\n"; $messageBody .= '<p>Name: ' . $_POST["name"] . '</p>' . "\n"; $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n"; $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n"; $messageBody .= '<p>----------------------------------------------------------' . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; $messageBody .= '<p>' . $_POST['message'] . '</p>' . "\n"; if($_POST["stripHTML"] == 'true'){ $messageBody = strip_tags($messageBody); } try{ if(!mail($owner_email, $subject, $messageBody, $headers)){ throw new Exception('mail failed'); }else{ echo 'mail sent'; } }catch(Exception $e){ echo $e->getMessage() ."\n"; } ?> |