PHP Email Form Issue

Discussion in 'Email' started by Victor, Mar 15, 2016.

  1. I am having an issue with my form which is base of a boostrap file.

    I have a contact.html with a contact_me.php which in turn validates the fields with contact_me.js

    I am using bootstrap. Both of the .php and .js files are under /bin & /js folders not in the root as the contact.html.

    I get the custom error from the .js file that the mail server is not responding; which it means that the message fail.

    I tried to add the items missing found here within my <?php ?> (see code) but I am new to php therefore I am not sure where to add it or how. Any pointers ???

    I also tried to follow this threat but at the end the user did not post how she solved the problem. :(

    Any ideas?

    Code below;

    <!-- Contact Form -->
      <!-- In order to set the email address and subject line for the contact form go to the bin/contact_me.php file. -->
      <div class="row">
                <div class="col-md-8 col-lg-offset-3 col-lg-6" id="contact-form">
                    <h3>Let us know what type of project do you need help with</h3>
                    <form name="sentMessage" id="contactForm" novalidate>
                        <div class="control-group form-group">
                            <div class="controls">
                                <label>Full Name:</label>
                                <input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
                                <p class="help-block"></p>
                        <div class="control-group form-group">
                            <div class="controls">
                                <label>Phone Number:</label>
                                <input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
                        <div class="control-group form-group">
                            <div class="controls">
                                <label>Email Address:</label>
                                <input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
                        <div class="control-group form-group">
                            <div class="controls">
                                <label>Project Details:</label>
                                <textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
                        <div id="success"></div>
                        <!-- For success/fail messages -->
                        <button type="submit" class="btn btn-primary">Send Message</button>
            <!-- /.row -->
            <!-- Footer -->
                <div class="row">
                    <div class="col-lg-12">
                        <p>Copyright &copy; Your Website 2014</p>
        <!-- /.container -->
        <!-- jQuery -->
        <script src="js/jquery.js"></script>
        <!-- Bootstrap Core JavaScript -->
        <script src="js/bootstrap.min.js"></script>
        <!-- Contact Form JavaScript -->
        <!-- Do not edit these files! In order to set the email address and subject line for the contact form go to the bin/contact_me.php file. -->
        <script src="js/jqBootstrapValidation.js"></script>
        <script src="js/contact_me.js"></script>


    // check if fields passed are empty
    if(empty($_POST['name'])      ||
    $_POST['phone'])      ||
    $_POST['email'])      ||
    $_POST['message'])   ||
    "No arguments Provided!";
    $name $_POST['name'];
    $phone $_POST['phone'];
    $email_address $_POST['email'];
    $message $_POST['message'];

    // Added code to work with SMTP

    require_once "Mail.php";
    $host "";
    $username "";
    $from_address "";
    $password "mypassword";
    $reply_to "";
    $port "587";

    // create email body and send it   
    $email_subject "Test: $name"// EDIT THE EMAIL SUBJECT LINE HERE
    $email_body "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
    $headers "From:\n";
    $headers .= "Reply-To: $email_address";   

    $smtp Mail::factory('smtp'$authe);
    $mail $smtp->send($to,$headers,$email_subject,$email_body);

    return true;       
      Jquery Validation using jqBootstrapValidation
      example is taken from jqBootstrapValidation docs
    $(function() {
      preventSubmit: true,
      submitError: function($form, event, errors) {
      // something to have when submit produces an error ?
      // Not decided if I need it yet
      submitSuccess: function($form, event) {
      event.preventDefault(); // prevent default submit behaviour
      // get values from FORM
      var name = $("input#name").val();
      var phone = $("input#phone").val();
      var email = $("input#email").val();
      var message = $("textarea#message").val();
      var firstName = name; // For Success/Failure Message
      // Check for white space in name for Success/Fail message
      if (firstName.indexOf(' ') >= 0) {
      firstName = name.split(' ').slice(0, -1).join(' ');
      url: "./bin/contact_me.php",
      type: "POST",
      data: {
      name: name,
      phone: phone,
      email: email,
      message: message
      cache: false,
      success: function() {
      // Success message
      $('#success').html("<div class='alert alert-success'>");
      $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
      $('#success > .alert-success')
      .append("<strong>Your message has been sent. </strong>");
      $('#success > .alert-success')
      //clear all fields
      error: function() {
      // Fail message                                                                              //This is where the error triggers
      $('#success').html("<div class='alert alert-danger'>");
      $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
      $('#success > .alert-danger').append("<strong>Sorry " + firstName + " it seems that my mail server is not responding...</strong> Could you please email me directly to <a href=' from;></a> ? Sorry for the inconvenience!");
      $('#success > .alert-danger').append('</div>');
      //clear all fields
      filter: function() {
      return $(this).is(":visible");
      $("a[data-toggle=\"tab\"]").click(function(e) {
    /*When clicking on Full hide fail/success boxes */
    $('#name').focus(function() {

Share This Page