Contact form, the mail does not arrive

2

My problem is that I have a form made with HTML, PHP and AJAX that I went up to my page does everything like "should" but my email does not get the message, I leave my code for review:

HTML:

<h3>Formulario de Contacto</h3>
      <div id="note"></div>
      <div id="fields">
        <form id="ajax-contact-form" action="javascript:alert('success!');">
          <div class="left">
            <input type="text" name="name" placeholder="Nombres Completos:" >
            <div class="clear"></div>
            <input type="text" name="email" placeholder="Su Correo:" >
            <div class="clear"></div>
            <input type="text" name="phone" placeholder="N&uacute;mero de Tel&eacute;fono">
            <div class="clear"></div>
            <div class="">
              <div class="left">
                <input class="capthca" type="text" name="capthca" value="Capthca:" onBlur="if(this.value=='') this.value='Capthca:'" onFocus="if(this.value =='Capthca:' ) this.value=''">
                <div class="clear"></div>
                <button type="submit" class="submit">submit</button>
              </div>
              <img src="captcha/captcha.php">
              <div class="clear"></div>
            </div>
          </div>
          <div class="left pad_left2">
            <textarea name="content" placeholder="Mensaje"></textarea>
            <div class="clear"></div>
          </div>
          <div class="clear"></div>
        </form>
      </div>
    </div> 

PHP:

<?php
include 'contact_config.php';
 session_start();
 error_reporting (E_ALL ^ E_NOTICE);
 $post = (!empty($_POST)) ? true : false;

 if($post)
 {
 include 'functions.php';

 $name = stripslashes($_POST['name']);
 $email = trim($_POST['email']);
 $phone = stripslashes($_POST['phone']);
 $subject = stripslashes($_POST['subject']);
 $message = "Site visitor information:

 Name: ".$_POST['name']
 ."

 E-mail Address: ".$_POST['email']
 ."

 Phone: ".$_POST['phone']
 ."

 Message: ".$_POST['content'];


 $error = '';

 // Check name

 if(!$name)
 {
 $error .= 'Please enter your First name.<br />';
 }
 // Check email

 if(!$email)
 {
 $error .= 'Please enter an e-mail address.<br />';
 }

 if($email && !ValidateEmail($email))
 {
 $error .= 'Please enter a valid e-mail address.<br />';
 }


 if(isset($_SESSION['captcha_keystring']) &&       strtolower($_SESSION['captcha_keystring']) != strtolower($_POST['capthca']))
 {
 $error .= "Incorect captcha.<br />";
 }
 if(!$error)
 {
 $mail = mail(WEBMASTER_EMAIL, $subject, $message,
 "From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());

 if($mail)
 {
 echo 'OK';
 }
 }
 else
 {
 echo '<div class="notification_error">'.$error.'</div>';
 }

 }
 ?>

JQUERY - AJAX

$(document).ready(function(){ 
$("#ajax-contact-form").submit(function(){
    var str = $(this).serialize(); 
    $.ajax( { type: "POST", url: "contact.php", data: str, success:  function(msg){ 
            if(msg == 'OK') // Message Sent? Show the 'Thank You' message  and hide the form
                { result = '<div class="notification_ok">Your message has been sent. Thank you!<br> <a href="#" onclick="freset();return false;">send another mail</a></div>'; $("#fields").hide(); }                           
            else
                { result = msg; } 
            $("#note").html(result); 
        } 
    }); 
    return false; 
}); 
});

function freset(){  
  $("#note").html('');
  document.getElementById('ajax-contact-form').reset();
  $("#fields").show();
 };

aside there is another doc .js

<?php
 // To
 define( '[email protected]', '[email protected]');
 ?>
    
asked by Aniuska 21.05.2016 в 07:05
source

2 answers

1

Have you made sure that your hosting provider has enabled the use of the mail function? Contact them to make sure.

If they have it enabled, you could show the errors it produces in order to refine the debugging a bit more.

Greetings!

    
answered by 06.06.2016 / 13:35
source
0

Try installing a local copy of your site using WAMP or XAMP to rule it out as a server or spam problem. I use Test Mail Server Tool to test mails sent via PHP locally (This tool is for Windows). If everything works well, it could be a problem of sending by the server or reception by the sender.

You must also bear in mind that the sender (from where the email is sent) must contain the same domain as the site. Otherwise there is a great chance that it will be marked as spam.

    
answered by 05.08.2016 в 15:53