为什么我的PHP联系表格根本不起作用?

时间:2014-05-01 06:01:58

标签: javascript php jquery ajax

我用不同的脚本测试了我网站的邮件 - 只是为了确保它不是主机,并且它运行正常。

我不确定为什么我的代码无效。除了html,我已经包含了我所有的联系论坛代码。它似乎没有加载php,因为当我输入无效的电子邮件等时它没有显示任何错误消息 - 它只是刷新它看起来的页面。

非常感谢帮助,谢谢大家。

 <!-- Contact Form Js -->
  <script type="text/javascript">                                 
    // contact form js
    jQuery(document).ready(function($) {
    $("#ajax-contact-form").submit(function() {
    var str = $(this).serialize();
    $.ajax({
      type: "POST",
      url: "inc/contact-process.php",
      data: str,
      success: function(msg) {
      // Message Sent? Show the 'Thank You' message and hide the form
      if(msg == 'OK') {
          result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
          $("#fields").hide();
          setTimeout("location.reload(true);",7000);
      } else {
          result = msg;
      }
      $('#note').html(result);
    }
    });
    return false;
    });
    });
   </script>   
   <!-- End Contact -->

PHP - 'contact-processes'

<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include dirname(dirname(__FILE__)).'/config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

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

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);


$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your 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 />';
}

// Check message (length)

if(!$message || strlen($message) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.<br />";
}


if(!$error)
{
ini_set("sendmail_from", WEBMASTER_EMAIL); // for windows server
$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>';
}

}
?>

PHP - 'functions'

<?php
function ValidateEmail($value)
{
    $regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';

    if($value == '') { 
        return false;
    } else {
        $string = preg_replace($regex, '', $value);
    }

    return empty($string) ? true : false;
}
?>

PHP - 'config'

<?php
define("WEBMASTER_EMAIL", 'snip@myemail.com');
?>

0 个答案:

没有答案