PHP - Php Contact Form Stopped Working - Help!
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 } ?> Similar Tutorialshi need some help, the following PHP script on my website has stopped working without me editing it : <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "contact@myemail.com"; $email_subject = "enquiry"; function died($error) { // your error code can go here echo "Sorry, but errors were found in the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['full_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['full_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br /><br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The Full Name you entered does not appear to be valid.<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.'; } 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 .= "Full Name: ".clean_string($first_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); ?> <!-- place your own success html below --> Thank you for contacting us, we will be in touch soon. <?php } die(); ?> which was working with the following form: <form name="htmlform" method="post" action="contact_uk.php"> <table style="background-color:whitesmoke; border:1px solid black; border-collapse:collapse" ;="" width="542px"> <tbody><tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="first_name">Full Name *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="full_name" maxlength="50" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="email">Email Address *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="email" maxlength="80" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="telephone">Telephone Number</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="telephone" maxlength="30" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="middle"> <label for="comments">Message *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <textarea name="comments" maxlength="1000" cols="22" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input value="Submit" type="submit"> </td> </tr> </tbody></table> </form> Now, I have tried the following test script found here (http://myphpform.com...not-working.php) and it does not work : <?php $from = "contact@myemail.com"; $headers = "From:" . $from; echo mail ("admin@awardspace.com" ,"testmailfunction" , "Oj",$headers); ?> so I have then contacted my Host which replied as follows: when you send emails by scripts and it is that our SMTP server requires authentication in order to send emails out. By using one of the emails that exist in the control panel as a sender/"from" header, you will be able to authenticate yourself and the SMTP server will send without problems. and provided this script, which works: <? $from = "From: You <contact@myemail.com>"; $to = "anymail@hotmail.com"; $subject = "Hi2! "; $body = "TEST"; if(mail($to,$subject,$body,$from)) echo "MAIL - OK"; else echo "MAIL FAILED"; ?> so can someone help me fix the code in the first quote I posted based on this last working one ? A few things maybe worth a mention: - previously, about a few weeks back, this form (first two quotes) was working perfectly as I've posted it and sending emails to my hotmail account without a hitch... - in the quotes "contact@myemail.com" is actually the domain email I have with the host thanks to anyone kind enough to help out... 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 <!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 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 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 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 I have a page that paginates results, i have a maximum of 6 per page before it goes to page number 2. now if i have enough results to warrent a page 2 it shows the pagination for 2 pages at tghe bottom. however when i click the number "2" i get the following in my URL Code: [Select] results.php?query=SELECT * FROM tests WHERE member_id='1' ORDER BY id DESC LIMIT 0, 8&page=8&limit=8 Here is my results.php page Code: [Select] <?php session_start(); include('Includes/auth.php'); require_once('header.php'); $connect = @mysql_connect("$host", "$username", "$password"); if (!($connect)) // If no connect, error and exit(). { echo("<p>Unable to connect to the database server.</p>"); exit(); } if (!(@mysql_select_db($database))) // If can't connect to database, error and exit(). { echo("<p>Unable to locate the $database.</p>"); exit(); } if (!($limit)){ $limit = 4;} // Default results per-page. if (!($page)){ $page = 0;} // Default page value. $numresults = mysql_query("SELECT * FROM gallery WHERE memberid=$_SESSION[SESS_MEMBER_ID]"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. if ($numrows == 0){ include('nogallery.php'); // bah, modify the "Not Found" error for your needs. exit();} $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows%$limit) { $pages++;} // has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) { $total = 1;} // If $pages is less than one or equal to 0, total pages is 1. else { $total = $pages;} // Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit;} //If not last results page, last result equals $page plus $limit. else{ $last = $numrows;} // If last results page, last result equals total number of results. //escape from PHP mode. ?> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf8"/> <title>Index</title> </head> <body class="cloudy"> <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="40%" valign="top"> <div align="right"><a href="myaccount.php"><img src="img/buttons/my_account.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" /><a href="addgallery.php"><img src="img/buttons/upload_image.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" border="0" /></div> <div class="content-box column-left"> <div class="content-box-header"> <h3>My Gallery</h3> </div><div class="content-box-content"><div><h4></h4> <table width="100%" border="0" cellpadding="0" cellspacing="4"> <tr> <td align="center" valign="top"><div><div> <h2>Showing <strong><?=$first?></strong> - <strong><?=$last?></strong> of <strong><?=$numrows?></strong></h2> </div> <table width="100%" border="0" cellspacing="4" cellpadding="4"> <?php $query = "SELECT * FROM gallery WHERE memberid='$_SESSION[SESS_MEMBER_ID]' ORDER BY id DESC LIMIT $page, $limit"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // reduces month output data to 3 digits $month=substr($month,0,3); // make sure we have a valid output if($id != "" && $id != null) echo "<td><table class='sample' width='85%' border='0' cellspacing='0' cellpadding='6'><tr align='center' height='100%' /><td height='220'><table height='100%' border='0' cellspacing='0' cellpadding='4'><tr><td>"; echo "<strong><span class='medium_text'>{$row['caption']}</span></strong></td></tr>"; //echo "<br />"; echo "<tr><td align='center' valign='middle'><a href='{$row['image']}' rel='facebox'><img class='gallery' src='{$row['thumb']}' /></a></td></tr>"; //echo "<br>"; echo "<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td><img src='img/icons/date.png' /> {$row['date']}</td><td><a href='remove-confirm.php?ID=<?php echo $encoded ?>' rel='facebox'><img src='img/icons/delete2.png' border='0' alt='Delete these results'/></a></td></tr></table></td></tr></table></td></tr></table>"; echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> <div align="center"><br> <?php if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">« Previous</a> \n");} for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b> \n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");} } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">Next »</a>\n");} ?> </div> </div></td> </tr> </table> </td> </tr> </table> <?php require_once('footer.php'); ?> </body> </html> i have been editing code and must of changed something previously and forgot to error check this page. but i cant find what i have changed. can someone see if i forgot something or removed something for me as i cant see where to look? many thanks. Why has this code stopped working, i had it working, but now it is not...........It is an update profile page but when i click save, it is trying to post my username to the database instead of the persons I am updating......help!!!!!!!! Code: [Select] <?php } //action: edit user ----------------------------------------------------------------------------- if (isset($_GET['edit']) && isset($_GET['id'])) { $userid = (int) $_GET['id']; if ($userid == 0) { die("Invalid ID provided."); } //execution when completed the edit user form and pressed submit button --------------------- if (isset($_POST['editUser'])) { //validate data ------------------------------------------------------------------------ //check email validation, the function is available at config.php //check both passwords are the same when password fields are not empty //end validate data --------------------------------------------------------------------- //save to database when no errors are detected ------------------------------------------ if (count($error) == 0) { $query = "UPDATE members SET username='".$username."', email='".$email."',name='".$name."', phone='".$phone."',address='".$address."', city='".$city."',state='".$state."', zip='".$zip."',cell='".$cell."', accounttype='".$accounttype."',badges='".$badges."', rank='".$rank."' WHERE userid='".$userid."' "; //update username session if you edit yourself if ($userid == $_SESSION['auth_admin_userid']) { $_SESSION['auth_admin_username'] = $username; } if (mysql_query($query)) { echo "<p><strong>User has been edited and saved to the database.</strong></p>"; } else { echo "<strong>User has NOT been edited and saved into the database. ".mysql_error()."</strong>"; } } } //get user from the database and put data into $_POST variables. $rs = mysql_query("SELECT name, username, phone, address, city, state, zip, cell, email, badges, rank, accounttype FROM members WHERE userid = ".$userid.""); if (mysql_num_rows($rs) == 0) { die("User does not exists!"); } $row = mysql_fetch_assoc($rs); $_POST['name'] = $row['name']; $_POST['username'] = $row['username']; $_POST['phone'] = $row['phone']; $_POST['address'] = $row['address']; $_POST['city'] = $row['city']; $_POST['state'] = $row['state']; $_POST['zip'] = $row['zip']; $_POST['cell'] = $row['cell']; $_POST['email'] = $row['email']; $_POST['badges'] = $row['badges']; $_POST['rank'] = $row['rank']; $_POST['accounttype'] = $row['accounttype']; //if is admin, then $_POST['admin'] exists ?> <div id="TabbedPanels1" class="TabbedPanels"> <ul class="TabbedPanelsTabGroup"> <li class="TabbedPanelsTab" tabindex="0">My Info</li> <li class="TabbedPanelsTab" tabindex="0">Merit Badges</li> <li class="TabbedPanelsTab" tabindex="0">Scout Rank</li> </ul> <div class="TabbedPanelsContentGroup"> <div class="TabbedPanelsContent"> <form action="admin.php?edit&id=<?php echo $userid;?>" method="post"> <table align="center" cellpadding="8" cellspacing="8"> <tr> <td><div align="right">Name:</div></td> <td> <p><input type="text" name="name" value='<?php echo $_POST['name'];?>' /> <?php echo(isset($error['name']))?$error['name']:"";?></p></td> </tr> <tr> <td>Phone Number:</td> <td><input type="text" name="phone" value='<?php echo $_POST['phone'];?>' /> <?php echo(isset($error['phone']))?$error['phone']:"";?></td> </tr> <tr> <td><div align="right">Address:</div></td> <td><input type="text" name="address" value='<?php echo $_POST['address'];?>' /> <?php echo(isset($error['address']))?$error['address']:"";?></td> </tr> <tr> <td><div align="right">City:</div></td> <td><input type="text" name="city" value='<?php echo $_POST['city'];?>' /> <?php echo(isset($error['city']))?$error['city']:"";?></td> </tr> <tr> <td><div align="right">State:</div></td> <td><input type="text" name="state" value='<?php echo $_POST['state'];?>' /> <?php echo(isset($error['state']))?$error['state']:"";?></td> </tr> <tr> <td><div align="right">Zip Code:</div></td> <td><input type="text" name="zip" value='<?php echo $_POST['zip'];?>' /> <?php echo(isset($error['zip']))?$error['zip']:"";?></td> </tr> <tr> <td><div align="right">Email:</div></td> <td> <p> <input type="text" name="email" value='<?php echo $_POST['email'];?>' /> <?php echo(isset($error['email']))?$error['email']:"";?></p></td> </tr> <tr> <td><div align="right">Cell Phone:</div></td> <td><input type="text" name="cell" value='<?php echo $_POST['cell'];?>' /> <?php echo(isset($error['cell']))?$error['cell']:"";?></td> </tr> <tr> <td class="aaaaaaa" align="right">Username:</td> <td><label for="username"></label> <input type="text" name="username" value='<?php echo $_POST['username'];?>' /> <?php echo(isset($error['username']))?$error['username']:"";?></p> </td> </tr> </table> <p> </p> <input name="editUser" type="submit" value="Save" /> <input type="hidden" name="userid" value="<?php echo $userid; ?>" /> </form> </div> <div class="TabbedPanelsContent"> <label for="badges"></label> <input name="badges" type="text" id="badges" value="<?php echo "$badges"; ?>" /> </div> <div class="TabbedPanelsContent"> <input name="rank" type="text" id="rank" value="<?php echo $rank; ?>" /> </div> </div> </div> <script type="text/javascript"> var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1"); </script> <?php } ?> I'm rewriting my aplication to work with mysqli and one function that I have created is not working anymore. I don't know why connection to db is not working anymore. It worked on mysql.
Can you see what is the problem?
function zamjena_broja($kataloski_broj){ global $conn_mysqli; $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysqli_query($conn_mysqli, $upit_zamjena) or die (mysqli_error($conn_mysqli)); while($row = mysqli_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); //var_dump($kataloski_broj); return $kataloski_broj; }My connection: <?php //Veza na bazu - mysqli protokol $DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100' $DBUser = 'xxxx'; $DBPass = 'xxxx'; $DBName = 'xxxdb'; $conn_mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); global $conn_mysqli; // check connection if ($conn_mysqli->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } ?> Had the following code working for months and now its not working anymore??? I dont't think the code is the correct way to do it but it did work, Can someone please look at it or give me the correct code. All I am trying to do is take the data from the form and email it to an email address and cc the user that filled out the form. I would like to add a bcc in the future. Here is my current code <?php $email = $_POST['EMAIL']; $mailto = "user@domain.com, user@domain.org"; $mailhead = "FROM: LOI<user@domain.org>"."\r\n"; $mailhead .= "Reply-To: user@domain.org"."\r\n"; $mailhead .= "CC: ".$email; $mailbody = "Values submitted from LOI:\n"; while (list($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; } mail($mailto, $mailsubj, $mailbody, $mailhead); header("LOCATION: letter.html"); ?> (my file structure is the following. inquiry.html has a form and the submit button goes to letter.php(code above) then it directs to letter.html) Thanks Trevor I am using this file with joomla. The database connection is code at the top of the php. I am getting the following error and I don't know why. Quote Warning: extract() [function.extract]: First argument should be an array in /usr/local/4admin/apache/vhosts/ladystestsite.com/httpdocs/php/obitdisplay.php on line 18 I have a query that is commented out and that will work, but I need the larger query to work. It has been working, but nothing has changed. The code below worked perfectly on my old hosting service. I've had to move to a new host and I get this error when I try to run the code. QuoteWarning: Cannot modify header information - headers already sent by (output started at ../user/dbconfig.php:11) This is the code:- <?php // connect to DATABASE! include_once('../user/dbconfig.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $options = [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::ATTR_EMULATE_PREPARES => false, ]; $dsn = "mysql:host=$host;dbname=$dbname;charset=$charset;port=$port"; try { // create a PDO connection with the configuration data $conn = new PDO($dsn, $user, $dbpassword, $options); } catch (PDOException $e) { // report error message echo $e->getMessage(); } $ans = $_POST['answer']; //Setup the filename that our CSV will have when it is downloaded. if($ans == 'yes'){ $fileName = 'answers-right.csv'; } elseif ($ans == 'no') { $fileName = 'answers-wrong.csv'; } // Create our SQL query. $sql = 'SELECT ID,email,firstname,lastname,message FROM checks WHERE answer = ?'; $stmt = $conn->prepare($sql); $stmt->execute([$ans]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // NB: now using fetchAll because there's going to be more than one record //Get the column names. $columnNames = array(); if(!empty($rows)){ //We only need to loop through the first row of our result //in order to collate the column names. $firstRow = $rows[0]; foreach($firstRow as $colName => $val){ $columnNames[] = $colName; } } //If the file exists and is writeable then delete it if(is_writable($fileName)){ //Delete the file $deleted = unlink($fileName); } //Set the Content-Type and Content-Disposition headers to force the download. header('Content-Type: application/excel'); header('Content-Type: application/excel Content-Disposition: attachment; filename="' . $fileName . '"'); //Open up a file pointer $fp = fopen('php://output', 'w'); //Start off by writing the column names to the file. fputcsv($fp, $columnNames); //Then, loop through the rows and write them to the CSV file. foreach ($rows as $row) { fputcsv($fp, $row); } //Close the file pointer. fclose($fp); ?> Would appreciate some help please? Hi
I wrote some basic custom php code that presents a form to a user, they submit their details and an email gets sent to me.
I checked and the fields from the form are being carried over.
Up to about a week ago it was working and now it has stopped working and I have no idea why.
I have checked with my isp and no changes were made to anything
php version is 5.2
Attached Files
php-ini.txt 1.07KB
1 downloads
contact-process.php 3.3KB
3 downloads I trying to make it so i can in put the data from a database into a theme i got from theme forest but im having few problems. the theme and page http://warp.nazwa.pl/dc/innovation/portfolio.html The NEXT button on the portfolio see how it slides across and works nicely here but on my page http://www.jigsawsoulmedia.com/root/Files/jigsawsoulmedia.com/_public/template.php its stopped working since I've place my php code in there and i can't see why not, everything look right to be from the html and php. Could one you lovely people see what you can spot wrong. page code with php below <!-- PAGE CONTENT HERE, PORTFOLIO LIST AND RIGHT SIDE BAR --> <div id="portoflioHeaderContainer"> <!-- PAGE TITLE AND NAVIGATION TREE --> <h1 class="commonPageTitle">Portfolio</h1> <div id="navigationTreeContainer"> <a href="index.html" class="prev">Home</a> \ <a class="current">Portfolio</a> </div> <!-- navigationTreeContainer --> <!-- SHORT TEXT THAT DESCRIBE PAGE CONTENT --> <p class="commonIntroductionText"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae. Nemo enim ipsam voluptatem quia <span class="spanBold">voluptas sit aspernatur</span> aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet consectetur, adipisci velit. </p> <!-- PORTFOLIO STATISTICS, CURRENT/ALL PAGE AND CURRENT/ALL PROJECT NUMBER --> <div class="portfolioStatisticsContainer"> <div class="pageStatsWrapper"> <span id="pageNumber"></span><span id="pageCount"></span> </div> <div class="imageStatsWrapper"> <span id="hoveredImageIndex">Project: 1/</span><span id="numberOfImages">0</span> </div> </div> <!-- portfolioStatisticsContainer --> </div> <!-- portoflioHeaderContainer --> <div id="portfolioContainer"> <div class="portfolioPage"> <?php $result = "SELECT * FROM portfolio"; $result = mysql_query ($result) or die (mysql_error()); $i=0; while($row = mysql_fetch_assoc($result)) { if($i==2) $divclass = 'portfolioProjectWrapper borderWhite'; else $divclass = 'portfolioProjectWrapper borderGray'; echo ' <div class="'.$divclass.'"> <a href="portfolioPage.html" class="image asyncImgLoad" title="img/'.$row['image290x290'].'"></a> <p class="imageDesc">'.$row['image290x290_phot'].'</p> <h3 class="title">'.$row['title'].'</h3> <p class="subtitle">'.$row['subtitle'].'</p> <p class="desc"> '.substr($row['description'], 0, 1200).' <a href="portfolioPage.html" class="commonLink">Read more</a> </p> </div> '; if($i==2) $i=0; else $i++; } ?> </div><!-- portfolioPage --> </div> <!-- portfolioContainer --> <!-- PORTFOLIO CONTROL PANEL --> <div id="portfolioControlPanel"> <div id="portfolioPrevPageBtn">Prev page</div> <div id="portfolioNextPageBtn">Next page</div> </div> <!-- portfolioControlPanel --> <div class="clearBoth"></div> Thanks for taking a look! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=351390.0 Friends on my few php scripts i used header('Location: somefile.php'); which worked just fine until yesterday the redirects stopped to work, im on a shared web hosting and the hosting people said they made no changes to their server, i tried error reporting but no error shows the pages which should actually do the redirection displays a blank page with no error warnings on it.
what could be the issue any idea?
We had to update our Linux server from php 5.4 to php 7.4. Something has changed and I have a feeling it is due to changes in fputcsv. When running the code below, instead of opening a csv file in libre calc, it fills the browser with the result. Is there a way of fixing this so I get the csv file again?
<code>date_default_timezone_set("America/New_York"); </code> Thanks for any help. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=330724.0 |