I created contact form which was working very wel but now it is not working ?
-
Hello,
I know I asked this question few months ago and I know it is php, but I learned a lot with searching and study in google and youtube and made this contact form which was working very wel few months ago.
I see the option everything else than WordPress so I try to ask this question with your understanding.
after all I made this contact form and it was working very good with sending and recieving email few months ago. I had tested it many times with sending email and it was OK. at the time I started to learn photoshop and I think I made some changes to this contact form which I don’t remember any more.
can some one help me to correct this bug .
when I fill the fields and let one field expresly empty it is not giving any error message which has to be.and I see I am not getiing any email any more?
I put the code in 2 sections to let you see beter.// define variables and set to empty values $nameErr = $emailErr = $phoneErr = $contentErr = ""; $name_sender = $email_sender= $phone = $content =$success= ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // post $name_sender = strip_tags($_POST['name_sender']); $email_sender = strip_tags($_POST['email_sender']); $phone = strip_tags($_POST['phone']); $content = strip_tags($_POST['content']); // validate name if (empty($_POST["name_sender"])) { $nameErr = "Name is required"; } else { $name_sender = test_input($_POST["name_sender"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z-' ]*$/",$name_sender)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email_sender"])) { $emailErr = "Email is required"; } else { $email_sender = test_input($_POST["email_sender"]); // check if e-mail address is well-formed if (!filter_var($email_sender, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } // validate phone if (empty($_POST["phone"])) { $phoneErr = "Phone is required"; } else { $phone = test_input($_POST["phone"]); // check if phone is well-formed if(!preg_match("/^[0-9\s\-]+$/", $phone)) { $phoneErr = "Invalid phone number"; } } // validate content if (empty($_POST["content"] )) { $contentErr = "Content is required"; } else { $content = test_input($_POST["content"]); } // send if ( empty($nameErr) && empty($emailErr) && empty($phoneErr) && empty($contentErr) ) { // Variables $to = 'johannes@webdesignleren.com'; $subject = 'Contact form'; echo '<script type="text/javascript">window.location.href="https://webdesignleren.com/bedankt/"</script>'; // Message content $content .= ''; // Headers $headers = 'From: ' .$name_sender. ' <' .$email_sender. '>' . PHP_EOL; $headers .= 'Reply-To: <' .$email_sender. '>' . PHP_EOL; $headers .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL; $headers .= 'Content-Type: text/plain; charset=UTF-8' . PHP_EOL; // Send email mail($to, $subject,$content, $headers); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // form ?>
this is the rest of code:
<div class="container-form"> <form id="contact" action= "https://webdesignleren.com/bedankt/" autocomplete="off" method="post" action=""> <h3>Quick Contact</h3> <h4>Contact us today, and get reply with in 24 hours!</h4> <fieldset> <input placeholder="Your name" type="text" name="name_sender" id="name_sender" value="<?php echo $name_sender;?>"> <span class="error">* <?php echo $nameErr; ?></span> </fieldset> <fieldset> <input placeholder="Your Email Address" type="text" name="email_sender" id="email_sender" value="<?php echo $email_sender;?>"> <span class="error">* <?php echo $emailErr; ?></span> </fieldset> <fieldset> <input placeholder="Your phone number" type="text" name="phone" id="phone" value="<?php echo $phone;?>"> <span class="error">* <?php echo $phoneErr; ?></span> </fieldset> <fieldset> <textarea placeholder="Type your message here.." type="text" name="content" id="content"><?php echo $content;?></textarea> <span class="error">* <?php echo $contentErr; ?></span> </fieldset> <fieldset> <button name="submit" type="submit" id="btnsubmit" class="submit">Submit</button></fieldset> </form></div>
I have carefully study this code in : https://tryphp.w3schools.com/showphp.php?filename=demo_form_validation_complete
where I took the most of code from here.but I couldn’t found the bug.
if some one can see where is the wrong please let me know.
thanksThe page I need help with: [log in to see the link]
- The topic ‘I created contact form which was working very wel but now it is not working ?’ is closed to new replies.