Jump to content

Pett

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Pett

  • Rank
    Newbie
  1. I have removed spaces and the error is still the same. About PHPMailer path, It is the path I had on my local server. Furthermore, would it really send an email to my email inbox if the path was incorrect? Am getting the email & I just need some help in making it redirect to another page after successful form submission.
  2. I tested it on localhost & its working fine & redirects to another page after sending email,,but on a live server it displays an error on the browser
  3. Hello ingolme, the content appearing before the warning message appears on the browser when I fill the form and hit the submit button. (You can visit pwebk.com/contact.php) & try it. I get the email in my inbox but it doesn't redirect to (thank_you.php page). ~ Or there could be a syntax error in my code? ~Regards..
  4. Hello dsonesuk, thanks for your help...I have tried your advice but the error persists, there aint any spaces before opening <?php tag and session PHP form <?php session_start(); //INITIALIZE VARIABLES and set to empty values $name = $phone = $email = $message= $captchaResults= ""; $nameErr = $phoneErr = $emailErr = $checkboxErr= $messageErr= $captchaErr= ""; ini_set('display_errors', 1); error_reporting(E_ALL); if ($_SERVER["REQUEST_METHOD"] == "POST") { $valid = true; //check if name is empty and performs functions in curly brackets if (empty($_POST["name"])) { $valid = false; $nameErr = "Please fill out this field"; } else { //Passes name throught test input function at the bottom of page $name = test_input($_POST["name"]); //remove illegal characters from name , Sanitize data $nm =filter_var($name, FILTER_SANITIZE_STRING); // Validate Data if (!preg_match("/^[a-zA-Z\s,.-]{3,30}$/", $nm)) // Regexp requiring letters, spaces, commas and fullstops and should not exceed 30 letters { $valid = false; $nameErr = "Please don't insert numbers*"; } } //check if phone contains numbers if (empty($_POST["phone"])) { $valid = false; $phoneErr = "Please fill out this field"; } else { $phone = test_input($_POST["phone"]); if (!preg_match("/^[0-9\s(),+.-]*$/", $phone)) { $valid = false; $phoneErr = "Please don't insert letters*"; } } //check if email is valid if (empty($_POST["email"])) { $valid = false; $emailErr = "Please fill out this field"; echo'email is empty<br>'; } else { $email = test_input($_POST["email"]); //Remove all illegal characters from email $em = filter_var($email, FILTER_SANITIZE_EMAIL); if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $em)) { $valid = false; $emailErr = "*Please insert a valid email address*"; } } // Check the values from checkbox and POST them to email $value= ""; // if (empty($_POST["checkbox"])) { $valid = false; $checkboxErr = "Please fill out this field*"; } else{ $checkbox =$_POST["checkbox"]; //Array of values from the checkbox values $value= implode(' , ', $checkbox); //implode values and separate by a comma $value = test_input($value); } //check if message contains letters and white-space if (empty($_POST["message"])) { $valid = false; $messageErr = "Please fill out this field"; echo 'Message is empty<br>'; } else { $message = test_input($_POST["message"]); //remove illegal characters from url $msg =filter_var($message, FILTER_SANITIZE_STRING); if (!preg_match("/^[a-zA-Z\s-,:;`~.?()]*$/", $msg)) //Regexp requiring spaces, full-stops, colon, semi-colons brackets, question marks { $valid = false; $messageErr = "Only letters and spaces are allowed*"; } } //Captcha Results $getRandomNumber1 = $_POST["firstRandomNumber"]; $getRandomNumber2 = $_POST["secondRandomNumber"]; $getCaptchaResults = $_POST["captchaResults"]; $totalNumber= $getRandomNumber1 + $getRandomNumber2; if($totalNumber == $getCaptchaResults){ echo''; } else{$valid = false; $captchaErr="Wrong Answer";} //stores name in a session variable to be used in thank-you page $_SESSION["nm"]= $nm; require ("PHPMailer/PHPMailerAutoload.php"); //including phpmailer class $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->SMTPDebug = 2; $mail->Host = "gator4261.hostgator.com"; // specify main and backup server, $mail->Port = 465; //Gmail SMTP port $mail->SMTPSecure = "ssl"; // Connect using a TLS connection $mail->SMTPAuth = true; // turn on SMTP authorization $mail->Username = "info@myemailaccount.com"; // SMTP username $mail->Password = "****************"; // SMTP password $mail->From = "$em"; //email of sender $mail->FromName = "$nm"; //name of the sender $mail->AddAddress("info@myemailaccount.com", "Petfar Designers"); //email address of recepient and name $mail->AddReplyTo($em, $nm); //Address to which recepient will reply $mail->WordWrap = 100; // set word wrap to 100 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = "Contact Form"; //subject of email $mail->Body = "Name: " . $nm . "<br>Phone: " . $phone . "<br>Email: " . $em . "<br>Subject: " . $value . "<br>Message: " . $msg ; //$mailphp = false; if ($valid) { // if (!$mailphp) { if (!$mail->Send()) { echo 'Form could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } else { header('Location:thank_you.php'); } } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> thank-you page <?php session_start(); ?> <!DOCTYPE html> <html lang= "en-US"> <head> <title> Thank_you_Page </title> </head> <body> <div class="container2"> <br> <br> <div class="thanks"> <b> Hello <i> <?php echo $_SESSION["nm"]; ?> </i> ,Your Contact form was successfully sent! One of our agents will reply to your query as soon as possible. <br> Thank you for choosing us </b> </div> <br> <br> <a href="contact.php"> Go Back </a> </div> </body> </html> Error 2017-03-05 05:15:33 CLIENT -> SERVER: EHLO pwebk.com 2017-03-05 05:15:33 CLIENT -> SERVER: AUTH LOGIN 2017-03-05 05:15:33 CLIENT -> SERVER: aW5mb0Bwd2Viay5jb20= 2017-03-05 05:15:33 CLIENT -> SERVER: RXN0aGVyNzIqMDcyMA== 2017-03-05 05:15:33 CLIENT -> SERVER: MAIL FROM: 2017-03-05 05:15:33 CLIENT -> SERVER: RCPT TO: 2017-03-05 05:15:33 CLIENT -> SERVER: DATA 2017-03-05 05:15:33 CLIENT -> SERVER: Date: Sat, 4 Mar 2017 23:15:32 -0600 2017-03-05 05:15:33 CLIENT -> SERVER: To: Patwan Website Solutions 2017-03-05 05:15:33 CLIENT -> SERVER: From: Martin njoguman 2017-03-05 05:15:33 CLIENT -> SERVER: Reply-To: Martin njoguman 2017-03-05 05:15:33 CLIENT -> SERVER: Subject: Contact Form 2017-03-05 05:15:33 CLIENT -> SERVER: Message-ID: <7bb49a9bd9cf546606a19fd015414116@pwebk.com> 2017-03-05 05:15:33 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer) 2017-03-05 05:15:33 CLIENT -> SERVER: MIME-Version: 1.0 2017-03-05 05:15:33 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1 2017-03-05 05:15:33 CLIENT -> SERVER: 2017-03-05 05:15:33 CLIENT -> SERVER: Name: Martin njoguman Phone: 123456 Email: mndungu739@gmail.com Subject: Website Design , 2017-03-05 05:15:33 CLIENT -> SERVER: Branding Message: Deqagst 2017-03-05 05:15:33 CLIENT -> SERVER: 2017-03-05 05:15:33 CLIENT -> SERVER: . 2017-03-05 05:15:33 CLIENT -> SERVER: QUIT Warning: Cannot modify header information - headers already sent by (output started at /home4/pwebken/public_html/PHPMailer/class.smtp.php:234) in /home4/pwebken/public_html/contact.php on line 157
  5. Hello all, I have a PHP contact form that is working fine on localhost. However when I upload it to a liveserver(hostgator) and test it, the user input gets submitted to my email inbox but sends an error message on the browser and refuses to redirect to another page(thank-you page). I am using PHPMailer class to send the form. PHP Form <?php session_start(); //INITIALIZE VARIABLES and set to empty values $name = $phone = $email = $message= $captchaResults= ""; $nameErr = $phoneErr = $emailErr = $checkboxErr= $messageErr= $captchaErr= ""; ini_set('display_errors', 1); error_reporting(E_ALL); if ($_SERVER["REQUEST_METHOD"] == "POST") { $valid = true; //check if name is empty and performs functions in curly brackets if (empty($_POST["name"])) { $valid = false; $nameErr = "Please fill out this field"; } else { //Passes name throught test input function at the bottom of page $name = test_input($_POST["name"]); //remove illegal characters from name , Sanitize data $nm =filter_var($name, FILTER_SANITIZE_STRING); // Validate Data if (!preg_match("/^[a-zA-Z\s,.-]{3,30}$/", $nm)) // Regexp requiring letters, spaces, commas and fullstops and should not exceed 30 letters { $valid = false; $nameErr = "Please don't insert numbers*"; } } //check if phone contains numbers if (empty($_POST["phone"])) { $valid = false; $phoneErr = "Please fill out this field"; } else { $phone = test_input($_POST["phone"]); if (!preg_match("/^[0-9\s(),+.-]*$/", $phone)) { $valid = false; $phoneErr = "Please don't insert letters*"; } } //check if email is valid if (empty($_POST["email"])) { $valid = false; $emailErr = "Please fill out this field"; echo'email is empty<br>'; } else { $email = test_input($_POST["email"]); //Remove all illegal characters from email $em = filter_var($email, FILTER_SANITIZE_EMAIL); if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $em)) { $valid = false; $emailErr = "*Please insert a valid email address*"; } } // Check the values from checkbox and POST them to email $value= ""; // if (empty($_POST["checkbox"])) { $valid = false; $checkboxErr = "Please fill out this field*"; } else{ $checkbox =$_POST["checkbox"]; //Array of values from the checkbox values $value= implode(' , ', $checkbox); //implode values and separate by a comma $value = test_input($value); } //check if message contains letters and white-space if (empty($_POST["message"])) { $valid = false; $messageErr = "Please fill out this field"; echo 'Message is empty<br>'; } else { $message = test_input($_POST["message"]); //remove illegal characters from url $msg =filter_var($message, FILTER_SANITIZE_STRING); if (!preg_match("/^[a-zA-Z\s-,:;`~.?()]*$/", $msg)) //Regexp requiring spaces, full-stops, colon, semi-colons brackets, question marks { $valid = false; $messageErr = "Only letters and spaces are allowed*"; } } //Captcha Results $getRandomNumber1 = $_POST["firstRandomNumber"]; $getRandomNumber2 = $_POST["secondRandomNumber"]; $getCaptchaResults = $_POST["captchaResults"]; $totalNumber= $getRandomNumber1 + $getRandomNumber2; if($totalNumber == $getCaptchaResults){ echo''; } else{$valid = false; $captchaErr="Wrong Answer";} //stores name in a session variable to be used in thank-you page $_SESSION["nm"]= $nm; require ("PHPMailer/PHPMailerAutoload.php"); //including phpmailer class $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->SMTPDebug = 2; $mail->Host = "gator4261.hostgator.com"; // specify main and backup server, $mail->Port = 465; //Gmail SMTP port $mail->SMTPSecure = "ssl"; // Connect using a TLS connection $mail->SMTPAuth = true; // turn on SMTP authorization $mail->Username = "info@myemailaccount.com"; // SMTP username $mail->Password = "****************"; // SMTP password $mail->From = "$em"; //email of sender $mail->FromName = "$nm"; //name of the sender $mail->AddAddress("info@myemailaccount.com", "Petfar Designers"); //email address of recepient and name $mail->AddReplyTo($em, $nm); //Address to which recepient will reply $mail->WordWrap = 100; // set word wrap to 100 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = "Contact Form"; //subject of email $mail->Body = "Name: " . $nm . "<br>Phone: " . $phone . "<br>Email: " . $em . "<br>Subject: " . $value . "<br>Message: " . $msg ; //$mailphp = false; if ($valid) { // if (!$mailphp) { if (!$mail->Send()) { echo 'Form could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } else { header('Location:thank_you.php'); } } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> thank-you form <?php session_start(); ?> <!DOCTYPE html> <html lang= "en-US"> <head> <title> Thank_you_Page </title> </head> <body> <div class="container2"> <br> <br> <div class="thanks"> <b> Hello <i> <?php echo $_SESSION["nm"]; ?> </i> ,Your Contact form was successfully sent! One of our agents will reply to your query as soon as possible. <br> Thank you for choosing us </b> </div> <br> <br> <a href="contact.php"> Go Back </a> </div> </body> </html> Error message on the browser Warning: Cannot modify header information - headers already sent by (output started at /home4/petansk/public_html/PHPMailer/class.smtp.php:234) in /home4/petansk/public_html/contact.php on line 157 Attached is the class.smtp.php in the PHPMailer classclass.smtp.php
  6. Here's what I've got: // Check the values from checkbox and POST them to email If (isset($_POST["checkbox"]) && !empty($_POST["checkbox"])) { $checkbox = array("Graphics Design", "Logo Design","Branding"); //loop through each checkbox value $value= implode(' , ', $checkbox); //implode values and separate by a comma } else { test_input($_POST["value"]); //POST values to email } Would you mind explaining using an example?
  7. Much appreciations for your help, I have taken into consideration your advice. But I need a helping hand concerning appending $value to the message body: PHP // Check the values from checkbox and POST them to email If (isset($_POST["checkbox"]) && !empty($_POST["checkbox"])) { $checkbox =$_POST["checkbox"]; //Array of values from the checkbox values $value= implode(' , ', $checkbox); //implode values and separate by a comma echo $value; } else { test_input($_POST["value"]); //POST values to email } Message body for the email $mail->Body = "Name: " . $_POST["name"] . "<br>Phone: " . $_POST["phone"] . "<br>Email: " . $_POST["email"] . "<br>Checkbox: " . $_POST["value"] . "<br>Package: " . $_POST["$package"]; HTML Form <br> <br> What project would you like for your institution? <span class= "error"> * </span> <br> <br> <input type="checkbox" class="input" name="checkbox[]" value="Graphics Design"> Graphics Design (Book, Posters, Flyers, Banners, Magazines, T-Shirts) <br> <input type="checkbox" class="input" name="checkbox[]" value="Logo Design" > Professional logo Design <br> <input type="checkbox" class="input" name="checkbox" value="Branding" > Branding
  8. Yah, I referred to the query since the member had a similar problem as mine. Am an online learner of PHP in W3Schools website and envatotuts and I refer to the tuts & queries when stack. Could you help me figure the problem out?
  9. Hey all... Am working on a PHP form which has got radio buttons, checkbox and text-area fields. When I hit the submit button, I get all the values in my email EXCEPT the checkbox values. Kindly help me rectify the error? PHP code <?php //INITIALIZE VARIABLES $name = $phone = $email = $value = $package = ""; $nameError = $phoneError = $emailError = $checkboxError = $packageError = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $valid = true; //checking name and validate using regexp if (empty($_POST["name"])) { $valid = false; $nameError = "Fill out this field"; } else { $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ,.-]*$/", $name)) { $valid = false; $nameError = "*Please insert Letters and white-spaces only*"; } } //check phone and validate if (empty($_POST["phone"])) { $valid = false; $phoneError = "Please fill out this field"; } else { $phone = test_input($_POST["phone"]); if (!preg_match("/^[0-9 ,+.-]*$/", $phone)) { $valid = false; $phoneError = "*Only numbers are allowed*"; } } //check validity of email if (empty($_POST["email"])) { $valid = false; $emailError = "Please fill out this field"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $valid = false; $emailError = "*Invalid email address*"; } } // Check the values from checkbox and POST them to email if(!empty($_POST["checkbox"])) //check if the user has selected a CHECKBOX or NOT { $checkbox =$_POST["checkbox"]; //Array of values from the checkbox foreach($checkbox as $value) //loop to store and display values of individual checkboxes {echo $value;}} //Display selected checkbox else {test_input($_POST["value"]);} //POST values to email //check package & validate if (empty($_POST["package"])) { $packageError = "Select one of these options"; } else { $package = test_input($_POST["package"]);} require ("PHPMailer/PHPMailerAutoload.php"); //Instantiate the Phpmailer class $mail = new PHPMailer(); $mail->IsSMTP(); // mailer to use SMTP $mail->SMTPDebug = 2; $mail->Host = "smtp.gmail.com"; // main and backup server $mail->SMTPSecure = "tls"; // TLS connection $mail->Port = 587; //Gmail SMTP port $mail->SMTPAuth = true; // turn on SMTP authorization $mail->Username = "gmail_address"; //username $mail->Password = "****************"; // password $mail->From = "$email"; //sender's email $mail->FromName = "$name"; //name $mail->AddAddress("gmail_address", "Pettans"); //email address of recepient and name $mail->AddReplyTo($_POST["email"], $_POST["name"]); //Address to which recepient will reply $mail->Subject = "Graphics Design Form"; //subject of email $mail->WordWrap = 120; //word wrap to 100 characters $mail->IsHTML(true); //email format to HTML $mail->Body = "Name: " . $_POST["name"] . "<br>Phone: " . $_POST["phone"] . "<br>Email: " . $_POST["email"] . "<br>Checkbox: " . $_POST["value"] . "<br>Package: " . $_POST["$package"]; if ($valid) { if (!$mail->Send()) { echo 'Form could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } else { header('Location:thanks.html'); } } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> HTML code <!DOCTYPE html> <html lang= "en-US"> <head> <meta name= "robots" content= "noindex, nofollow"> <meta charset="utf-8"> <meta name= "author" content= "Pettans Designers"> <meta name= "viewport" content= "width=device=width, initial scale= 1.0"> <link href= "style.css" rel= "stylesheet" type= "text/css"> <title> Graphics Design Form </title> </head> <body> <image src= "images/logo.gif" border= "0" width= "240px" height="160px"> <br> <div class="form2"> <form method= "post" action= "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <font color="white"> <h4>Please fill the form below to kick start your project. <br> <br> <font size="4.5px" color="red"> *required field </font> </h4> <br> Your name? <input type= "text" class= "input" name= "name" placeholder= "e.g Pettans Designers" value="<?php echo $name; ?>" required> <span class= "error"> * <br> <?php echo $nameError; ?> </span> <br> <br> Your phone number? <input type= "text" class= "input" name= "phone" value="<?php echo $phone; ?>" placeholder= "e.g 0722222222" required> <span class= "error"> * <br> <?php echo $phoneError; ?> </span> <br> <br> Your email address? <input type= "email" class= "input" name= "email" placeholder= "will not be published" value="<?php echo $email; ?>" required> <span class= "error"> * <br> <?php echo $emailError; ?> </span> <br> <br> What project would you like for your institution? <span class= "error"> * </span> <br> <br> <input type="checkbox" class="input" name="checkbox[]" value="Graphics Design"> Graphics Design (Book, Posters, Flyers, Banners, Magazines, T-Shirts) <br> <input type="checkbox" class="input" name="checkbox[]" value="Logo Design" > Professional logo Design <br> <input type="checkbox" class="input" name="checkbox[]" value="Branding" > Branding <br> <br> How did you know about our institution? <span class= "error"> * </span> <br> <br> <input type ="radio" class= "input" name="package" <?php if (isset($package) && $package == "mouth") echo "checked";?> value= "mouth" required> Word of Mouth <br> <input type ="radio" class= "input" name="package" <?php if (isset($package) && $package == "reputation") echo "checked";?> value= "website"> Reputation <br> <input type ="radio" class= "input" name="package" <?php if (isset($package) && $package == "newspaper") echo "checked";?> value= "newspaper"> Newspaper <br> <br> <button class="submit" type= "reset" value= "Reset"> Reset Form </button> <button class="submit" type= "submit" value= "Submit"> Submit Form </button> </font> </form> </div> </body> </html>
×