好的,所以我在我的网站上有这个表格,当我测试它并尝试发送一封电子邮件时,它说邮件已经发送但是我把它发送到我的电子邮件......
以下是代码:
contact.php:
<?php
function ValidateEmail($email)
{
$regex = '/([a-z0-9_.-]+)'. # name
'@'. # at
'([a-z0-9.-]+){1,255}'. # domain & possibly subdomains
'.'. # period
"([a-z]+){2,10}/i"; # domain extension
if($email == '') {
return false;
}
else {
$eregi = preg_replace($regex, '', $email);
}
return empty($eregi) ? true : false;
}
include 'config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
$name = stripslashes($_POST['name']);
$email = $_POST['email'];
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$error = '';
if(!$name)
{
$error .= '<p>Please enter your name.</p>';
}
if(!$email)
{
$error .= '<p>Please enter an e-mail address.</p>';
}
if($email && !ValidateEmail($email))
{
$error .= '<p>Please enter a valid e-mail address.</p>';
}
if(!$subject || strlen($subject) < 2)
{
$error .= "<p>Please enter the subject.</p>";
}
if(!$message || strlen($message) < 2)
{
$error .= "<p>Please enter your message.</p>";
}
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 id="notification">'.$error.'</div>';
}
}
&GT;
的config.php:
<?php
// Change this to your email account
define("WEBMASTER_EMAIL", 'my mail address');
&GT;
form.js:
$(document).ready(function(){
$("#contactForm").submit(function(){
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "contact.php",
data: str,
success: function(msg){
$("#note").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
result = '<div id="notification"><p>Your message has been sent. Thank you!</p></div>';
$('#contactForm').each (function(){
this.reset();
});
}
else
{
result = msg;
}
$(this).html(result);
});
}
});
return false;
});
});
谢谢!
答案 0 :(得分:0)
更改var str = $(this).serialize();数据:$(“#contactForm”)。serialize(),