Jump to content

Contact Form Not Working, any idea why?


Zola

Recommended Posts

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 by Zola
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.