3 votes

Contact form, the mail does not arrive

My problem is that I have a form made with HTML, PHP and AJAX that I upload to my page does everything as "should" but my mail 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( 'ejemplo@gmail.com', 'ejemplo@gmail.com');
 ?>
 

2voto

ErnestoRM Points 1653

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.

A greeting!

0voto

Hubyx Reds Points 1

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

You must keep in mind also that the sender (from where the mail will be sent) must contain the same domain as the site. Otherwise there is a great possibility of being flagged as spam.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X