Zola Posted February 6, 2014 Share Posted February 6, 2014 (edited) Hello, I am trying to get a little contact form working with a bootstrap 3 theme, but the data is not being sent to my email. If anyone can spot anything obvious as to why its not working (or any ways to make this code much better), I would really appreciate it. <?php if (isset($_POST['submit'])) { $to = 'myemail@email.com'; $subject = "WEBSITE ENQUIRY"; $name_field = $_POST['name']; $email_field = $_POST['email']; $phone_field = $_POST['phone']; $message = $_POST['message']; if (strlen(trim($message)) > 0) { $body = "From: $name_field \n E-Mail: $email_field \n Phone: $phone_field \n Message: $message \n "; if (mail($to, $subject, $body)) { echo "<h3>Thanks! Your email has been sent. <br />I will answer your enquiry as soon as possible.</h3> <hr>"; } else { echo 'Cannot sent mail'; } } else { echo "<h4>Failed to Send Mail. <br><br>Please ensure that all fields are filled out in order to email us.</h4><hr>"; } } ?> <div class="col-sm-8"> <p>If you wish to ask a question about a potential project please get in touch via the form below, or from the details on the right.</p> <form role="form" method="POST" action="contact.php"> <div class="row"> <div class="form-group col-md-12"> <label for="Name">Name</label> <input type="text" name="name" class="form-control" id="input1"> </div> <div class="form-group col-md-12"> <label for="Email">Email Address</label> <input type="email" name="email" class="form-control" id="input2"> </div> <div class="form-group col-md-12"> <label for="Phone">Phone Number</label> <input type="phone" name="phone" class="form-control" id="input3"> </div> <div class="clearfix"></div> <div class="form-group col-lg-12"> <label for="Message">Message</label> <textarea name="message" class="form-control" rows="6" id="input4"></textarea> </div> <div class="form-group col-lg-12"> <input type="hidden" name="save" value="contact"> <button type="submit" class="btn btn-primary pull-right">Submit</button> <div class="clearfix"></div> </div> </div> </form> Edited February 6, 2014 by Zola Quote Link to comment Share on other sites More sharing options...
gristoi Posted February 6, 2014 Share Posted February 6, 2014 is your server set up to use smtp, also: <button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button> Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2014 Share Posted February 7, 2014 mail() depends on the configuration of your specific server, and the underlying mail transfer agent mechanics. I don't see anything obviously wrong with your code, although there could be something subtle. If the mail() function is succeeding, you need to debug at the MTA level. For example, if you were on a linux server and the mail is being dumped off to sendmail or postfix there are ways to determine if the mta is successfully delivering the mail. Mail server configuration also includes details about DNS MX, SPF and DKIM, not to mention the core SMTP standard. If you're just developing on a local workstation its probable that you don't have a working mail configuration OR you do have one, and the mail is being delivered, but due to the lack of the aforementioned environment, your mail is being spam filtered or outright rejected. Quote Link to comment Share on other sites More sharing options...
Zola Posted February 7, 2014 Author Share Posted February 7, 2014 is your server set up to use smtp, also: <button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button> That was the very problem!!! Thanks for your replies guys. Much appreciated!! 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.