clintrivest Posted December 15, 2017 Share Posted December 15, 2017 Hi everyone! I'm almost ready to launch my website promoting my computer training business. Unfortunately, I'm having trouble with my contact form. As far as I can tell, it should be working. I've had others examine it as well, and say it should work. I know PHPMailer is working on my server, I did a test. Following is the code for the html and php: HTML <form id="form" method="POST" action="bat/contact.php"> <div class="success_wrapper"> <div class="success">Contact form submitted!<br> <strong>We will be in touch soon.</strong> </div></div> <fieldset> <label class="name"> <input type="text" value="Name:"> <br class="clear"> <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span> </label> <label class="email"> <input type="text" value="E-mail:"> <br class="clear"> <span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label> <label class="phone"> <input type="tel" value="Phone:"> <br class="clear"> <span class="error error-empty">*This is not a valid phone number.</span><span class="empty error-empty">*This field is required.</span> </label> <label class="message"> <textarea>Message:</textarea> <br class="clear"> <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label> <div class="clear"></div> <div class="btns"><a data-type="reset" class="btn">clear</a><a data-type="submit" class="btn">submit</a> <div class="clear"></div> </div></fieldset></form> PHP: <?php if(isset($_POST['submit'])) { // EDIT THE 2 LINES BELOW AS REQUIRED //$email_to = "crivest@solsticetraining.ca"; $email_to = "crivest@solsticetraining.ca"; // EDIT THE 2 LINES BELOW AS REQUIRED //$sender = "crivest@solsticetraining.ca"; $sender = "crivest@solsticetraining.ca"; $name = $_POST['name']; // required $email = $_POST['email']; // required $phone = $_POST['phone']; // required $message = $_POST['message']; // required $email_message = "Form details below.\n\n"; $email_subject = "Contact details - $name"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Phone: ".clean_string($phone)."\n"; $email_message .= "Message: ".clean_string($message)."\n"; // create email headers $headers = 'From:'.$sender."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); $sent= @mail($email_to, $email_subject, $email_message, $headers); if($sent){ echo "<script>alert('Contact form submitted! We will be in touch soon.') location.replace('index4.html') </script>"; } else { echo "<script>alert('Sorry! Something went wrong') location.replace('index-4.html') </script>"; } } ?> Maybe I'm missing something obvious. First, I'd like to see the form actually work. Then I can worry about security. The form can be seen at www.solsticetraining.ca/index-4.html Thanks for all the help! Quote Link to comment Share on other sites More sharing options...
requinix Posted December 15, 2017 Share Posted December 15, 2017 You know PHPMailer works but you're not using it? You should. That could easily fix your problem. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 15, 2017 Share Posted December 15, 2017 It may work better if you give names to your form's input fields 1 Quote Link to comment Share on other sites More sharing options...
cutielou22 Posted April 30, 2019 Share Posted April 30, 2019 Your form inputs do need the name="name" and name="email" added for your $_POSTS. Also, this is just to educate me. Why did you add a "@" in front of the mail()? I looked it up and I couldn't find anything telling me what this means. Thanks! Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted April 30, 2019 Share Posted April 30, 2019 6 minutes ago, cutielou22 said: Also, this is just to educate me. Why did you add a "@" in front of the mail()? I looked it up and I couldn't find anything telling me what this means. Thanks! It's probably better not to know. ? The @ symbol is for error suppression. More information can be found here:https://www.php.net/manual/en/language.operators.errorcontrol.php 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.