我确信这是一个已被多次回答的问题,但在我花了数小时试图找出问题后,我的联系表仍然存在问题。
当我提交表单时,我会被重定向到带有谢谢消息的 submit.php 页面,但是没有电子邮件发送到我的 $email_to 地址。
可能值得注意的是,此代码位于 Wordpress 主题中,并且当前正在我的本地计算机上运行(但这会影响任何事情吗?)
谁能告诉我我在这里做错了什么?我有一种感觉我使用的插件不正确,这个 ajax 游戏很新!
我正在使用以下插件:
- Jquery 表单插件 (http://pastebin.com/cC5899ns)
- Jquery 验证 (http://pastebin.com/GyYuVwAH)
这是我的 HTML:
<div id="footer">
<h3>Contact</h3>
<div id="preview"></div>
<form name="form" id="form" action="<?php bloginfo('template_directory'); ?>/_/inc/submit.php" method="post">
<input type="text" value="Your name" name="name" />
<input type="tel" value="Your contact number" name="email" />
<textarea name="message">Quick Note</textarea>
<button>Submit</button>
</form>
</div>
我的 JS:
$(document).ready(function (){
$('#form').validate(
{
rules:
{
"name":{
required:true,
maxlength:40
},
"email":{
required:true,
email:true,
maxlength:100
},
"message":{
required:true
}},
messages:
{
"name":{
required:"This field is required"
},
"email":{
required:"This field is required",
email:"Please enter a valid email address"
},
"message":{
required:"This field is required"
}},
submitHandler: function(form){
$(form).ajaxSubmit({
target: '#preview',
success: function() {
alert('hello');
$('#foooter').slideUp('fast');
}
});
}
})
});
我的提交.php
<?php
include("db.php");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name=mysql_real_escape_string($_POST['name']);
$email=mysql_real_escape_string($_POST['email']);
$message=mysql_real_escape_string($_POST['message']);
if(strlen($name)>0 && strlen($email)>0 && strlen($message)>0)
{
$email_to = "*********";
$email_from = $email;
$email_subject = "Contact Form";
$email_message = stripslashes($message);
$headers = 'From: '.$email_from."\r\n" .
'Reply-To: '.$email_from."\r\n";
mail($email_to, $email_subject, $email_message, $headers);
$time=time();
mysql_query("INSERT INTO contact (name,email,message,created_date) VALUES('$name','$email','$message','$time')");
echo "<h1>Thank You !</h1>";
}
}
?>
我的 db.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "*****";
$mysql_database = "******";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
?>