mikebyrne Posted July 20, 2018 Share Posted July 20, 2018 I'm using a template which contains a form so users can email me, but it doesn't seem to be working. Any ideas why?? I've changed "me@myemailaddress.com" to my own! <?php //Prefedined Variables $to = "me@myemailaddress.com"; // Email Subject $subject = "Contact from Your Site"; // This IF condition is for improving security and Prevent Direct Access to the Mail Script. if ($_POST) { // Collect POST data from form $name = stripslashes($_POST['fname']); $email = stripslashes($_POST['email']); $phone = stripslashes($_POST['phone']); $message = stripslashes($_POST['msg']); //$realcap = stripslashes($_POST['captcha']); $ipAddress = $_SERVER['REMOTE_ADDR']; if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { $ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); } // Collecting all content in HTML Table $content = '<table width="100%"> <tr><td align "center"><b>Contact Details</b></td></tr> <tr><td>Name:</td><td> ' . $name . '</td></tr> <tr><td>Email:</td><td> ' . $email . ' </td></tr> <tr><td>Phone:</td><td> ' . $phone . ' </td></tr> <tr><td>Message:</td> <td> ' . $message . '</td></tr> <tr><td>Date:</td> <td> ' . date('d-m-Y') . '</td></tr> <tr><td>IP:</td> <td> ' . $ipAddress . '</td></tr> </table> '; // Define email variables $headers = "From:" . $email . "\r\n"; $headers .= "Reply-to:" . $email . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8'; if (!empty($name) && !empty($email) && !empty($content)) { // Sending Email if (mail($to, $subject, $content, $headers)) { print "Thank you, I will getback to you shortly<br>"; return true; } else { print "Some errors to send the mail."; return false; } } else { print "Some validation errors to send the mail."; return false; } } Quote Link to comment Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 "Doesn't seem to be working" is absolutely useless information for us. Of course it isn't working. It's why you made this thread. How is it not working? Which message do you see? What have you tried to troubleshoot or solve the problem on your own? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 When I press the Submit button, no error msg appears ie like: "some errors to the send mail" Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 20, 2018 Share Posted July 20, 2018 so, does that mean you are getting a blank page after you press the submit button? if so, what is the code for your form? Quote Link to comment Share on other sites More sharing options...
maxxd Posted July 20, 2018 Share Posted July 20, 2018 Also, you might want to look into PHPMailer - it's safer and more reliable than PHP's native mail() function, and it has debugging options for situations just like this. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 You might also want to note that the "From" address must be a mailbox on the sending domain. Quote Link to comment Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 (edited) To add to all that, your use of returns confuses me. How is this file run? Do you know that return only matters if the code is inside a function or include/require-d from somewhere else? edit: return can end a file early, but a return value only matters in the above two cases. Edited July 20, 2018 by requinix Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 20, 2018 Share Posted July 20, 2018 Do you know that there are no other syntax-type errors going on? Do you have PHP error checking turned on and displaying errors during development on your screen? Try putting an echo ahead of the call to the mail function to be sure that you are getting that far. Basic debugging process. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 4 hours ago, mac_gyver said: so, does that mean you are getting a blank page after you press the submit button? if so, what is the code for your form? No, the page stays on the form with all the text etc still in the fields Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 4 hours ago, mac_gyver said: what is the code for your form? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 11 minutes ago, Barand said: <!-- our services --> <section id="contact" class="bg-light-teal"> <div class="content-boxed"> <div class="split-color wow fadeInLeft"> <div class="section-number">#05</div> <h2 class="section-heading rotate">Contact</h2> </div> <div class="container-fluid"> <div class="row"> <div class="col-lg-6"> <div class="pr-5 mb-5 wow fadeInUp"> <div class="gmap behind-border-box"><iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d2401.5623741248505!2d-6.9729973!3d52.9922718!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x485d6f8aac9336c9%3A0x35a64aae423e6da9!2sIrish+Web+Services!5e0!3m2!1sen!2sin!4v1531902216161" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> </div> </div> </div> <div class="col-lg-6"> <div class="wow fadeInRight"> <h3>let’s get in touch</h3> <div class="contact-form"> <form id="contact_form"> <div class="f-field"><input name="fname" type="text" placeholder="Name" required></div> <div class="f-field"><input name="email" type="text" placeholder="Email" required></div> <div class="f-field"><input name="phone" type="text" placeholder="Phone" required></div> <div class="f-field"><textarea name="msg" placeholder="Message"></textarea></div> <div class="sent-btn"><input name="submit" type="submit" value="Submit"></div> </form> </div> </div> </div> </div> </div> <h2 class="section-heading2">Contact</h2> </div> </section> <!-- our contact --> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 20, 2018 Share Posted July 20, 2018 your form is not a post method form, so there is no $_POST data. add method='post' to the <form ... > tag. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 57 minutes ago, mac_gyver said: your form is not a post method form, so there is no $_POST data. add method='post' to the <form ... > tag. <form id="contact_form" method='post'> <div class="f-field"><input name="fname" type="text" placeholder="Name" required></div> <div class="f-field"><input name="email" type="text" placeholder="Email" required></div> <div class="f-field"><input name="phone" type="text" placeholder="Phone" required></div> <div class="f-field"><textarea name="msg" placeholder="Message"></textarea></div> <div class="sent-btn"><input name="submit" type="submit" value="Submit"></div> </form> Still the same result. No error msg etc Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 Without an "action" attribute it is assumed that the processing code is on the same page as the form (ie the page calls itself). is that the case? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 1 minute ago, Barand said: Without an "action" attribute it is assumed that the processing code is on the same page as the form (ie the page calls itself). is that the case? No, its on a separate page called contactsubmit.php Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 (edited) Then you need to tell the form that it's on that page. Edited July 20, 2018 by Barand Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted July 20, 2018 Author Share Posted July 20, 2018 Something like this: <form id="contact_form" method='post' action='contactsubmit.php'> Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 Yep 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.