我正在使用下面的代码向我的地址发送一封电子邮件,提醒我有新用户注册:
<?php
$errors = '';
$myemail = 'name@mydomain.com';
if (empty($_POST['email']) || empty($_POST['email']) || empty($_POST['email'])) {
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address
)) {
$errors .= "\n Error: Invalid email address";
}
if (empty($errors)) {
$to = $myemail;
$email_subject = "Invitation Request: $email_address";
$email_body = "has received a new invitation request. " .
"\n Email: $email_address";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);
//redirect to the 'thank you' page
}
?>
目前它将用户重定向到一个新页面,但我希望它允许 javascript 弹出成功/失败消息,就像现代网站中使用的那样。
这是消息代码(CSS 和 Javascript):
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<style type="text/css">
/* Status Message */
.message {
display: none;
margin: 0 0 13px 0;
padding: 13px 13px 13px 52px;
background: url('icon_check.gif') left no-repeat #EFA;
background-position: 13px 5px;
border: solid 1px #BD8; '
width: 300px;
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#Button1").click(function(event){
$(".message").show();
$(".message").fadeOut(2500);
});
});
</script>
这是成功消息的 html:
<div class="message">Your Invitation Request Has Been Received!</div>
是否有可能做到这一点?在过去的两天里,我在几个地方寻找答案,但我似乎无法改变正确的事情。任何帮助,将不胜感激。